我想更改数据中某些列的格式(类).将对象(mydf
)从charactor帧到factor帧.
我不想在read.table()
倍函数读取文本文件时这样做.
任何帮助都将不胜感激.
我想更改数据中某些列的格式(类).将对象(mydf
)从charactor帧到factor帧.
我不想在read.table()
倍函数读取文本文件时这样做.
任何帮助都将不胜感激.
嗨,欢迎来到R的世界.
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
这也适用于字符、日期、整数和其他类
Since you're new to R I'd suggest you have a look at these two websites:
R reference manuals:
R Reference card: http://cran.r-project.org/doc/contrib/Short-refcard.pdf