例如将如下数据转换成data.frame型:
l <- replicate(
5,
list(sample(letters, 4)),
simplify = FALSE
)
=>
-
用unlist拆分list后重构矩阵然后转换为data.frame
lr <- data.frame(matrix(unlist(l), nrow=5, byrow=T),stringsAsFactors=FALSE)
-
lapply 函数和sapply函数
data.frame(matrix(lapply(l,as.character),nrow=5))
data.frame(matrix(t(sapply(l,c)),nrow=5))