How can we split a matrix columnwise to a list?
m <- matrix(rnorm(10 * 2), ncol = 2)
The first solution uses a double conversion via a data.frame:
as.list(as.data.frame(m))
The second uses split:
split(x=t(m), f=1:ncol(m))
The third solution works with lapply:
lapply( seq_len(ncol(m)), function(k) m[,k])
Donnerstag, 13. September 2012
Abonnieren
Kommentare zum Post (Atom)
Keine Kommentare:
Kommentar veröffentlichen