r - Converting a list of named elements into a data frame or data table -


i have list of named elements (testlist) of names duplicated

$x [1] "one"  $x [1] "two"  $y [1] "three"  $y [1] "four" 

and trying end data table combine elements common names same column.

     x     y 1: 1 3 2: 2  4 

i have tried

testdf <- do.call(cbind, lapply(testlist, data.table)) 

but end with:

   x.v1 x.v1  y.v1 y.v1 1:  1  2 3 4 

any suggestions? appreciate help!

try

library(data.table)#v1.9.5+ dcast(setdt(stack(testlist))[, n:= 1:.n, ind],                   n~ind, value.var='values')[,n:=null][] #    x     y #1: 1 3 #2: 2  4 

or base r approach be

unstack(stack(testlist),values~ind) #   x     y #1 1 3 #2 2  4 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -