【发布时间】:2018-07-21 19:20:17
【问题描述】:
我正在尝试通过从列表中提取值来创建数据框。我有一个 157 列表,其中包含不相等的值,如图所示
我想要的是在一个数据帧中 rbind 的所有列表值。我尝试通过 for 循环执行此操作,但它只存储了第一个列表值。
我能做的是:
porturn1=data.table::rbindlist(lapply(porturn[1], as.data.frame), idcol = "id")
porturn2=data.table::rbindlist(lapply(porturn[2], as.data.frame), idcol = "id")
porturn3=data.table::rbindlist(lapply(porturn[3], as.data.frame), idcol = "id")
porturn4=data.table::rbindlist(lapply(porturn[4], as.data.frame), idcol = "id")
porturn5=data.table::rbindlist(lapply(porturn[5], as.data.frame), idcol = "id")
然后将rbind.fill 命令应用于所有这些数据,但这似乎很麻烦且不切实际。虽然rbind.fill之后的结果是我想要的,如图:
如何创建循环来创建所需的数据框(如上图所示,我需要存储 157 个列表值或 157 行)?
【问题讨论】: