我是R的新手,正在尝试阅读csv。该文档显示了一个函数read.csv()
。但是,当我读取文件并检查变量的类型时,它会显示一个列表。文档将其显示为data.frame
。有人可以解释为什么会这样吗?
到目前为止,我的代码:
mytable<-read.csv(InputFile,header=TRUE,stringsAsFactors=FALSE)
dim(mytable)
typeof(mytable)
输出:
dim(mytable)
[1] 500 20
typeof(mytable)
[1] "list"
最佳答案
如答案https://stackoverflow.com/a/6258536/8900683中所述。
在R
中,每个“对象”都有一个mode
和class
。前者表示对象在内存中的存储方式(数字,字符,列表和函数),而后者则表示其抽象类型。
例如:
d <- data.frame(V1=c(1,2))
class(d)
# [1] "data.frame"
mode(d)
# [1] "list"
typeof(d)
# list
关于读取R中的CSV作为data.frame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26961328/