问题说明了一切 - 我想获取一个充满 data.frames 的列表对象,并将每个 data.frame 写入一个单独的 .csv 文件,其中 .csv 文件的名称对应于列表对象的名称。
这是一个可重现的示例以及我迄今为止编写的代码。
df <- data.frame(
var1 = sample(1:10, 6, replace = TRUE)
, var2 = sample(LETTERS[1:2], 6, replace = TRUE)
, theday = c(1,1,2,2,3,3)
)
df.daily <- split(df, df$theday) #Split into separate days
lapply(df.daily, function(x){write.table(x, file = paste(names(x), ".csv", sep = ""), row.names = FALSE, sep = ",")})
这是 R 吐出的错误消息的顶部
Error: Results must have one or more dimensions.
In addition: Warning messages:
1: In if (file == "") file <- stdout() else if (is.character(file)) { :
the condition has length > 1 and only the first element will be used
我在这里缺少什么?