Answers for "r dataframe column factor"

R
1

r dataframe column factor

mtcars  #look at this built in data set
str(mtcars) #allows you to see the classes of the variables (all numeric)

#one approach it to index with the $ sign and the as.factor function
mtcars$am <- as.factor(mtcars$am)
#another approach
mtcars[, 'cyl'] <- as.factor(mtcars[, 'cyl'])
str(mtcars)  # now look at the classes
Posted by: Guest on November-30-2020

Code answers related to "r dataframe column factor"

Browse Popular Code Answers by Language