[R] rbind in array of lists

Rui Barradas ruipbarradas at sapo.pt
Sun Oct 12 19:31:41 CEST 2014


Hello,

Em 12-10-2014 18:26, David Winsemius escreveu:
>
> On Oct 12, 2014, at 8:45 AM, Rui Barradas wrote:
>
>> Hello,
>>
>> Try the following.
>>
>> do.call(rbind, lapply(a, '[[', "var1"))
>> do.call(rbind, lapply(a, '[[', "var2"))
>
> Could perhaps (untested) make it more general with:
>
> do.call(rbind, lapply(a, '[[', names(a[[1]])[1]))
> do.call(rbind, lapply(a, '[[', names(a[[1]])[2]))
>
> And then seeing that, could perhaps make it a one-liner with:
>
> lapply( names(a[[1]]),   function(nm) do.call(rbind, lapply(a, '[[', nm)) )

Yes, I had thought of

lapply(seq_along(a[[1]]), function(i) do.call(rbind, lapply(a, '[[', i)))


Rui Barradas
>



More information about the R-help mailing list