[R] The "reverse" of do.call("rbind",) on a list
Sebastian P. Luque
spluque at gmail.com
Tue Nov 13 02:17:36 CET 2007
On Tue, 13 Nov 2007 02:07:39 +0100,
Søren Højsgaard <Soren.Hojsgaard at agrsci.dk> wrote:
> Dear List, I want to turn the matrix
>> xm
> [,1] [,2] [1,] "a" "b" [2,] "d" "e"
> into a list "by rows" as: [[1]] [1] "a" "b" [[2]] [1] "d" "e"
> A (bad?) way of doing this is as
>> unlist(apply(xm,1, list), recursive=F)
> [[1]] [1] "a" "b" [[2]] [1] "d" "e"
> - but there must be a more elegant way. Can anyone help on this?
How about:
lapply(seq(nrow(xm)), function(k) xm[k, ])
?
--
Seb
More information about the R-help
mailing list