【发布时间】:2016-08-23 15:08:50
【问题描述】:
我从 R 开始,并尝试将一些数据组织成这样的嵌套列表:
library(readr)
dataframe1 <- read_csv2("sampleData.csv", col_names = FALSE)
# convert dataframe to a nested list
width <- ncol(sampleData)
nestedList <- list()
for(i in 1:width){
nestedList[[i]] = list(name=dataframe1[1, i], attribute1 = dataframe1[2, i], attribute2 = dataframe1[3, i], attribute3 = dataframe1[4, i])
}
当我尝试访问列表中的元素时,它们总是显示为小标题,如下所示:
> nestedList[[1]]$name
# A tibble: 1 x 1
X1
<chr>
1 B06_01
所以列表看起来确实是列表,但为什么单个元素会自动成为小标题? (我知道tibble 是一个增强的数据框类。)为什么它们不是向量?另外,我注意到即使是数值在嵌套列表中也会以“chr”结尾。
【问题讨论】:
-
因为 data.frame1 是使用
readr的read_csv2函数读入的。该函数默认导入tbl类的数据。
标签: r data-structures