Chcę połączyć kolumny listy w pojedynczym dataframe, jednak niektóre listy mają różne długości. Maksymalna długość wynosi 17 i pomyślałem o sposobie wokół tego i to tworząc nowe ...

r
1
no_'t'-lime 15 marzec 2021, 14:25

1 odpowiedź

Najlepsza odpowiedź

Możesz użyć merge i jak masz wiele kolumn, które należy dodać, możesz go nazwać za pomocą Reduce.

Reduce(function(x,y) merge(x,y, all=TRUE), test.enc)
#   layer pland_01_evergreen_needleleaf pland_02_evergreen_broadleaf pland_03_deciduous_needleleaf pland_04_deciduous_broadleaf pland_05_mixed_forest pland_06_closed_shrubland pland_07_open_shrubland pland_08_woody_savanna pland_09_savanna pland_10_grassland pland_11_wetland pland_12_cropland pland_13_urban pland_14_mosiac pland_15_barren
#1      1                   0.016832782                           NA                    0.02247306                  0.023755599           0.020535776                        NA              0.02398351             0.02348951       0.02451150         0.02410480       0.02610454        0.02474816     0.02505420      0.02445531      0.02546954
#2      2                   0.024552628                           NA                    0.02722547                  0.025067363           0.024129970                        NA              0.01960245             0.02542422       0.02634385         0.02576757       0.02700779        0.02699291     0.02497892      0.02656089      0.02602178
#3      3                   0.024377985                           NA                    0.01792343                  0.021518223           0.022502727               0.005861055                      NA             0.02228443       0.02307849         0.02233838       0.02289677        0.02332125     0.02193252      0.02307542      0.02782941
#4      4                   0.009584417                           NA                            NA                  0.007147367           0.009856845                        NA                      NA             0.01032240       0.01038415         0.01890686       0.01991228        0.02099358     0.01740502      0.01267376      0.02209821
#5      5                   0.013569500                           NA                            NA                           NA                    NA               0.024770236              0.02754707             0.01152029       0.01126311         0.02613909       0.02279769        0.02766299     0.01984815      0.02088688      0.02322232
#6      6                   0.021745836                           NA                            NA                  0.029096943           0.031107209               0.021715635              0.02052899             0.02285806       0.02186569         0.02614542       0.02753060        0.02675260     0.02730401      0.02645434      0.02774609
#7      7                   0.024301743                   0.02329869                    0.02333604                  0.026786033           0.025282676               0.026614709              0.02528710             0.02613250       0.02632935         0.02625906       0.02713345        0.02646590     0.02613483      0.02714906      0.02809451
#8      8                   0.028323187                           NA                    0.02897722                  0.027053462           0.027173697                        NA                      NA             0.02693391       0.02723777         0.02734769       0.02850656        0.02769111     0.02743155      0.02755093      0.03081885
#9      9                   0.029710995                           NA                    0.02793198                  0.026721715           0.028330379                        NA                      NA             0.02729057       0.02775900         0.02820165       0.02819870        0.02770472     0.02840401      0.02748702      0.02839908
#10    10                   0.020706332                           NA                    0.02406840                  0.023870960           0.022946509               0.027355719              0.02251452             0.02434459       0.02481852         0.02497496       0.02356305        0.02582980     0.02553579      0.02603021      0.02829662
#11    11                   0.025760934                   0.02910651                    0.01935547                  0.024907433           0.026238719               0.022478951                      NA             0.02630855       0.02647103         0.02690171       0.02355663        0.02937620     0.02766807      0.02945142      0.02927011
#12    12                   0.025148797                   0.04234851                    0.02796495                  0.030461899           0.034980814                        NA                      NA             0.03157723       0.03117850         0.03092764       0.02726627        0.03044017     0.02830097      0.03173588      0.02484902
#13    13                   0.028520806                   0.02788104                    0.02693961                  0.026020952           0.026978507               0.031480399              0.02774477             0.02736679       0.02776470         0.02800810       0.02425478        0.02972730     0.02739477      0.03036292      0.02023138
#14    14                   0.021327549                   0.01899742                    0.01857191                  0.015865887           0.017803204               0.019968816                      NA             0.01709176       0.01829664         0.01715720       0.02022095        0.01913202     0.01918466      0.01910547      0.02730348
#15    15                   0.024794668                   0.02639924                    0.01854253                  0.024333800           0.025141407               0.025004067              0.02731504             0.02451662       0.02432407         0.02470640       0.02296538        0.02230048     0.02257370      0.02213324      0.02525440
#16    16                   0.027986949                   0.02601143                    0.01270995                  0.020117980           0.023795555               0.024064520              0.03727955             0.02304373       0.02697939         0.02297320       0.01895232        0.03104189     0.01855721      0.03329877      0.01238752
#17    17                   0.022970945                   0.03166427                    0.04239139                  0.033222898           0.034979964               0.028908655              0.02582697             0.03024807       0.02614318         0.02717176       0.01633074        0.01945524     0.02669124      0.01538465      0.02437832
1
GKi 15 marzec 2021, 11:43