[R] reshape non-square matrix

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Sat Mar 1 07:38:34 CET 2014


library(reshape2)
mx <- matrix( 1:12, nrow=3 )
mxdf <- melt( mx )
names( mxdf ) <- c( "m", "n", "value" )

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

On February 28, 2014 5:49:26 PM PST, Chirag Gupta <cxg040 at email.uark.edu> wrote:
>Hi list
>
>I have a matrix of size m x n (m and n are different, hence non
>square!)
>I want to melt it in such a way that I get a df of 3 columns. m ,n and
>cell
>value in the original matrix.
>
>Any suggestions?




More information about the R-help mailing list