0
我有一个列表清单list_of_lists
。与数据框具有不同长度和类型的子列表的列表R
每个SUB_LIST可以有不同的长度理论上,如:
list_of_lists[[1]]
$id = 1
$variable1 = "8"
$variable2 = 8 12.2
和...
list_of_lists[[2]]
$id = 2
$variable1 = "4"
$variable2 = 2 2.2 12.1 200.1
我想给list_of_lists
转换为长数据帧。已经看过this SO post:
b = as.data.frame(matrix(unlist(list_of_lists), nrow=length(unlist(list_of_lists[1]))))
,并尝试这样的:
long_df = ldply(list_of_lists, as.data.frame)
也不如我所料它的工作原理。
我想有一个长的像DF:
id variable1 variable2
1 "8" 8
1 "8" 12.2
2 "4" 2
2 "4" 2.2
2 "4" 12.1
2 "4" 200.1