【发布时间】:2018-12-09 07:03:04
【问题描述】:
我将一堆 docx 文件加载到一个列表中,然后尝试将生成的列表列表转换为数据框。
下面的可重现示例不读取 docx 文件,它只是演示了我编写的 lapply 代码
# Creating a list to somewhat
# replicate the list of lists
# I get from lapply read_docx
a <- c("1","0","art","3","4")
x <- cbind(as.data.frame(a),as.data.frame(a),as.data.frame(a))
b <- c("a", "b", "c")
names(x) = b
y <- as.list(x)
shingled <- as.data.frame("a")
names(shingled) = "vaaar"
# putting together each list in
# y into a single data frame
# Note: even though as.data.frame(y[1])
# gives, surprise surprise, a data frame,
# the code below returns a list
all <- lapply(y, function(x){
exer <- as.data.frame(x)
names(exer) = "vaaar"
shingled <- rbind(shingled,
exer)}
)
此处提供了相同的代码: https://pastebin.com/rw24jaMN
【问题讨论】:
-
您的预期输出是什么?如果你能提供,那么建议解决方案会更容易。