【发布时间】:2018-02-11 17:14:43
【问题描述】:
我有一个数据框列表:
lists <- replicate(10, as.data.frame(matrix(rnorm(100), 10, 10)), simplify = FALSE)
names(lists) <- LETTERS[1:10]
我想将所有数据帧写入一个根据它们在 R 中的对象名称命名的单独文件。我尝试使用 lapply 和 paste,但这非常失败:
lapply(lists, function(x) write.table(x, file=paste(x,".txt"), sep="\t"))
Error in file(file, ifelse(append, "a", "w")) :
invalid 'description' argument
In addition: Warning message:
In if (file == "") file <- stdout() else if (is.character(file)) { :
the condition has length > 1 and only the first element will be used
Called from: file(file, ifelse(append, "a", "w"))
如何在不为 n 个 data.frames 写 n 行的情况下做到这一点?
【问题讨论】: