将列表组合成data.frame结果嵌套列表而不是列

时间:2015-05-24 04:29:44

标签: r

我正在尝试将名为source_namescommunities的两个列表连接到一个名为names的列表中,然后将其存储为数据帧列,但我不断深入嵌套列表。我做错了什么?

我的代码:

> communities<-as.list(as.character(V(g)[(length(df[,1])+1):length(V(g))]))
> head(communities,5)
[[1]]
[1] "122"

[[2]]
[1] "123"

[[3]]
[1] "124"

[[4]]
[1] "125"

[[5]]
[1] "126"

> source_names<-as.list(df[,1])
> head(source_names,5)
[[1]]
[1] "11170"

[[2]]
[1] "2840"

[[3]]
[1] "32595"

[[4]]
[1] "45410"

[[5]]
[1] "52720"

> names<-c(source_names,communities)#force names to include communities
> names
[[1]]
[1] "11170"

[[2]]
[1] "2840"

[[3]]
[1] "32595"

[[4]]
[1] "45410"

[[5]]
[1] "52720"

[[6]]
[1] "61720"

[[7]]
[1] "7180"

[[8]]
[1] "81990"

[[9]]
[1] "93445"

[[10]]
[1] "102250"

[[11]]
[1] "111965"

[[12]]
[1] "123345"

[[13]]
[1] "134480"

[[14]]
[1] "142225"

[[15]]
[1] "153870"

[[16]]
[1] "162460"

[[17]]
[1] "171705"

[[18]]
[1] "182480"

[[19]]
[1] "193495"

[[20]]
[1] "201870"

[[21]]
[1] "214620"

[[22]]
[1] "22240"

[[23]]
[1] "231305"

[[24]]
[1] "240"

[[25]]
[1] "250"

[[26]]
[1] "266585"

[[27]]
[1] "276490"

[[28]]
[1] "281840"

[[29]]
[1] "293340"

[[30]]
[1] "305970"

[[31]]
[1] "313450"

[[32]]
[1] "323005"

[[33]]
[1] "332550"

[[34]]
[1] "34130"

[[35]]
[1] "350"

[[36]]
[1] "36580"

[[37]]
[1] "371395"

[[38]]
[1] "383595"

[[39]]
[1] "39455"

[[40]]
[1] "407385"

[[41]]
[1] "413170"

[[42]]
[1] "42580"

[[43]]
[1] "436890"

[[44]]
[1] "44295"

[[45]]
[1] "45730"

[[46]]
[1] "461005"

[[47]]
[1] "47605"

[[48]]
[1] "480"

[[49]]
[1] "495775"

[[50]]
[1] "501580"

[[51]]
[1] "510"

[[52]]
[1] "52645"

[[53]]
[1] "533510"

[[54]]
[1] "541620"

[[55]]
[1] "554870"

[[56]]
[1] "563855"

[[57]]
[1] "57210"

[[58]]
[1] "58700"

[[59]]
[1] "592460"

[[60]]
[1] "606840"

[[61]]
[1] "613490"

[[62]]
[1] "621910"

[[63]]
[1] "634475"

[[64]]
[1] "649665"

[[65]]
[1] "651060"

[[66]]
[1] "664735"

[[67]]
[1] "674325"

[[68]]
[1] "684580"

[[69]]
[1] "692950"

[[70]]
[1] "702805"

[[71]]
[1] "712435"

[[72]]
[1] "721080"

[[73]]
[1] "731330"

[[74]]
[1] "747575"

[[75]]
[1] "751675"

[[76]]
[1] "764560"

[[77]]
[1] "772385"

[[78]]
[1] "784215"

[[79]]
[1] "791705"

[[80]]
[1] "805420"

[[81]]
[1] "811950"

[[82]]
[1] "823120"

[[83]]
[1] "8310350"

[[84]]
[1] "844910"

[[85]]
[1] "85630"

[[86]]
[1] "86590"

[[87]]
[1] "875575"

[[88]]
[1] "888575"

[[89]]
[1] "891525"

[[90]]
[1] "905415"

[[91]]
[1] "914020"

[[92]]
[1] "92785"

[[93]]
[1] "930"

[[94]]
[1] "941615"

[[95]]
[1] "957770"

[[96]]
[1] "968065"

[[97]]
[1] "975225"

[[98]]
[1] "984015"

[[99]]
[1] "993880"

[[100]]
[1] "1002280"

[[101]]
[1] "101845"

[[102]]
[1] "102645"

[[103]]
[1] "1031220"

[[104]]
[1] "1042723"

[[105]]
[1] "1053670"

[[106]]
[1] "1060"

[[107]]
[1] "10780"

[[108]]
[1] "1080"

[[109]]
[1] "1091335"

[[110]]
[1] "1101805"

[[111]]
[1] "111270"

[[112]]
[1] "112480"

[[113]]
[1] "1131910"

[[114]]
[1] "1142585"

[[115]]
[1] "1150"

[[116]]
[1] "1160"

[[117]]
[1] "1171370"

[[118]]
[1] "1181725"

[[119]]
[1] "1190"

[[120]]
[1] "1200"

[[121]]
[1] "1210"

[[122]]
[1] "122"

[[123]]
[1] "123"

[[124]]
[1] "124"

[[125]]
[1] "125"

[[126]]
[1] "126"

[[127]]
[1] "127"

[[128]]
[1] "128"

[[129]]
[1] "129"

[[130]]
[1] "130"

[[131]]
[1] "131"

[[132]]
[1] "132"

[[133]]
[1] "133"

[[134]]
[1] "134"

[[135]]
[1] "135"

我的预期输出:

> names
11170
2840
32595
45410
52720
122
123
124
125
126

1 个答案:

答案 0 :(得分:1)

只需unlist

names <- unlist(c(source_names, communities))
data.frame(names)
#   names
#1  11170
#2   2840
#3  32595
#4  45410
#5  52720
#6    122
#7    123
#8    124
#9    125
#10   126