[英]Read a CSV in R as a data.frame
I am new to R and trying to read a csv.我是 R 新手,正在尝试阅读 csv。 The documentation shows a function
read.csv()
.该文档显示了一个函数
read.csv()
。 However, when I read the file and check the type of the variable it shows a list.但是,当我读取文件并检查变量的类型时,它会显示一个列表。 Documentation shows it as a
data.frame
.文档将其显示为
data.frame
。 Can someone explain why it happens that way?有人可以解释为什么会这样吗?
My code so far:到目前为止我的代码:
mytable<-read.csv(InputFile,header=TRUE,stringsAsFactors=FALSE)
dim(mytable)
typeof(mytable)
Output:输出:
dim(mytable)
[1] 500 20
typeof(mytable)
[1] "list"
As it is explained in the answer https://stackoverflow.com/a/6258536/8900683 .正如答案https://stackoverflow.com/a/6258536/8900683 中所解释的那样。 In
R
every "object" has a mode
and a class
.在
R
每个“对象”都有一个mode
和一个class
。 The former represents how an object is stored in memory ( numeric , character , list and function ) while the later represents its abstract type.前者表示对象在内存中的存储方式(数字、字符、列表和函数),而后者表示其抽象类型。
For example:例如:
d <- data.frame(V1=c(1,2))
class(d)
# [1] "data.frame"
mode(d)
# [1] "list"
typeof(d)
# list
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.