我们得到length
of list
元素('indx')通过循环sapply
。在最近的版本中R
, 我们可以用lengths
来替换sapply(.., length)
步。我们改变length
每个元素的max
'indexx' 的长度 (length<-
)从而垫NA
末尾的值list
长度小于的元素max
长度。我们可以rbind
the list
元素,转换为data.frame
并更改列名称。
indx <- sapply(lst, length)
#indx <- lengths(lst)
res <- as.data.frame(do.call(rbind,lapply(lst, `length<-`,
max(indx))))
colnames(res) <- names(lst[[which.max(indx)]])
res
# sk ques pval diff imp
#1 10 sfsf 0.05 <NA> <NA>
#2 24 wwww 0.11 0.3 <NA>
#3 24 wwww 0.11 0.3 2
data
lst <- list(structure(c("10", "sfsf", "0.05"), .Names = c("sk", "ques",
"pval")), structure(c("24", "wwww", "0.11", "0.3"), .Names = c("sk",
"ques", "pval", "diff")), structure(c("24", "wwww", "0.11", "0.3",
"2"), .Names = c("sk", "ques", "pval", "diff", "imp")))