Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR R

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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #dataframe #column #factor
ADD COMMENT
Topic
Name
6+7 =