一个类似的问题确实有类似的问题,但看起来有一些错字,它没有使用正确的函数,它是未知的,它不是一个数据框架。我的是作为一个列表从表结构的。csv文件中读取。我也尝试过在do的rbind选项。在这个问题中建议调用,但没有工作,所以它被注释掉了,它仍然显示为typeof()下的列表。
这是一个公共的Google电子表格这里是我的可复制代码:# Read study file
getwd()
bank <- read.csv("attemptCSV.csv")
bank
typeof(bank)
bank <- data.frame(bank)
typeof(bank)
colnames(bank)
#do.call(rbind.data.frame, bank)
#typeof(bank)
#> typeof(bank)
#[1] "list"
#> bank <- data.frame(bank)
#> typeof(bank)
#[1] "list"
#> colnames(bank)
# [1] "age" "job" "marital" "education" "default" "balance" "housing" "loan"
# [9] "contact" "day" "month" "duration" "campaign" "pdays" "previous" #"poutcome"
#[17] "y"
应该是class
而不是typeof
,因为根据?typeof
typeof决定了任何对象的(R internal)类型或存储方式
class(bank)
检查
> data(iris)
> typeof(iris)
[1] "list"
> class(iris)
[1] "data.frame"
> is.list(iris)
[1] TRUE
> is.data.frame(iris)
[1] TRUE
原因还在于data.frame
是具有相同长度元素(columns
)的list