[R] how to vectorize a matrix
Martin Maechler
maechler at stat.math.ethz.ch
Mon May 22 12:32:31 CEST 2006
>>>>> "Christian" == Christian Ritz <ritz at kvl.dk>
>>>>> on Mon, 22 May 2006 11:17:32 +0200 writes:
Christian> Hi Lorenzo,
Christian> maybe the following example is of use?
Christian> a <- matrix(1:25,5,5)
Christian> stack(as.data.frame(a[, c(1,3,5,2,4)]))
Christian> Note that 'stack' takes a data frame or list as first argument (not a
Christian> matrix). Therefore the matrix is first converted to a data frame using
Christian> 'as.data.frame'.
I do wonder though if not simply
> c(a[, c(1,3,5,2,4)])
[1] 1 2 3 4 5 11 12 13 14 15 21 22 23 24 25 6 7 8 9 10 16 17 18 19 20
is enough for Lorenzo, in this case ??
Martin
More information about the R-help
mailing list