Change data type of one column in R

0 votes
I have a data frame of two columns, one with data type character and the other with numeric. Now I want to change the data type of one column from numeric to factorial. Is that possible?
Dec 11, 2018 in Data Analytics by Ali
• 10,670 points
510 views

2 answers to this question.

0 votes

Try this:

dataframeName$colName <- as.factor(datataframeName$colName)

answered Dec 11, 2018 by Maverick
• 10,820 points
0 votes
You can change data types using as.* where * is the datatype to change to, the other way is using class().

class(df$var) = "Numeric".

The above method works only for a few combinations.
answered Aug 16, 2019 by anonymous
• 32,460 points

Related Questions In Data Analytics

0 votes
1 answer

Is it possible to change the column names of the dataset that I'm using in R?

That is definitely possible in R. You ...READ MORE

answered Dec 17, 2018 in Data Analytics by Anisha

edited Dec 17, 2018 80 views
0 votes
2 answers

How to change the value of a variable using R programming in a data frame?

You are getting this error since the ...READ MORE

answered Aug 16, 2019 in Data Analytics by anonymous
• 32,460 points
7,082 views
0 votes
1 answer

How to replace all occurrences of a character in a character column in a data frame in R

If you used sub() to replace the ...READ MORE

answered Jun 28, 2019 in Data Analytics by anonymous
• 32,460 points
3,298 views
0 votes
2 answers

How to change column names of a Data frame?

Try this way - names(data frame) <- ...READ MORE

answered Aug 26, 2019 in Data Analytics by anonymous
• 32,460 points
176 views
+9 votes
3 answers

Which is a better initiative to learn data science: Python or R?

Well it truly depends on your requirement, If ...READ MORE

answered Aug 8, 2018 in Data Analytics by Abhi
• 3,680 points
148 views
0 votes
1 answer

Error saying "vector size cannot be NA" when using R with data mining

You can use the removesparseterm function.  Removes sparse ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,820 points
1,099 views
+1 vote
2 answers
0 votes
1 answer

Trying to find frequent itemsets of a data set using arules package

Try replacing ID <- c("A123","A123","A123","A123","B456","B456","B456") item <- c("bread", "butter", "milk", ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,820 points
74 views
0 votes
1 answer

Clean a set of data using R

Try this: NCM <- c(5,1,3,2,4) Mbrand <- c(1,5,3,4,2) fac<-factor(Mbrand, levels ...READ MORE

answered Nov 13, 2018 in Data Analytics by Maverick
• 10,820 points
81 views
0 votes
1 answer

Replace comma with a period in data cleaning using R

You can use the scan function in ...READ MORE

answered Nov 13, 2018 in Data Analytics by Maverick
• 10,820 points
446 views