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