这个问题已经说得很清楚了 - 我想要将一个装满data.frames的列表对象写入到单独的.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
我在这里漏掉了什么?