[R] flatten a matrix and unflatten it

From: Bill Simpson <William.Simpson_at_drdc-rddc.gc.ca>
Date: Tue 22 Mar 2005 - 08:44:22 EST


I want to flatten a matrix and unflatten it again. Please tell me how to do it.

  1. given a matrix: x1 y1 z1 x2 y2 z2
    ...
    xk yk zk convert it to a vector: x1, y1, z1, x2, y2, z2, ..., xk, yk, zk
  2. given a vector: x1, y1, z1, x2, y2, z2, ..., xk, yk, zk convert it to a matrix x1 y1 z1 x2 y2 z2
    ...
    xk yk zk

It is known that the number of dimensions is 3.

Thanks for any help!

Bill



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Mar 22 08:49:11 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:52 EST