【发布时间】:2017-07-30 09:38:46
【问题描述】:
为了学习 R,我尝试导入包含在纯文本文件中的数据(关于垃圾邮件)。
我使用了table函数,然后尝试将对应的对象转换为数据框,使用this问题的两个答案。
这里是代码。
file <- "./spam.data.txt"
spamd <- read.table(file, sep = "" , header = F, stringsAsFactors= F)
spamd <- as.data.frame(spamd)
typeof(spamd) # list
spamd <- read.table(file, sep = "" , header = F, stringsAsFactors= F)
spamd <- as.data.frame.matrix(spamd)
typeof(spamd) # list
为什么在这两种情况下,typeof() 返回list?为什么不是数据框?
谢谢
【问题讨论】:
-
您需要了解 R 中的数据结构的更多信息。请查看
class(spamd)。请注意,read.table被记录为返回一个 data.frame。无需转换,
标签: r list dataframe data-structures