Re: [R] Converting a Matrix to a Vector

2009-03-25 Thread Patrizio Frederic
try also m <- matrix( runif(5^2), nrow=5, dimnames = Names<- list( c("A","B","C","D","E"), c("O","P","Q","R","S") ) ) data.frame(expand.grid(Names[[1]],Names[[2]]),as.numeric(m)) data.frame(code=outer(Names[[1]],Names[[2]],paste,sep=".")[1:25],num=as.numeric(m)) Patrizio 2009/3/25 jim holtma

Re: [R] Converting a Matrix to a Vector

2009-03-25 Thread jim holtman
Use the 'reshape' package: > library(reshape) > melt(m) X1 X2 value 1 A O 0.26550866 2 B O 0.37212390 3 C O 0.57285336 4 D O 0.90820779 5 E O 0.20168193 6 A P 0.89838968 7 B P 0.94467527 8 C P 0.66079779 9 D P 0.62911404 10 E P 0.06178627 11 A Q 0.20597457 12

Re: [R] Converting a Matrix to a Vector

2009-03-25 Thread Berwin A Turlach
G'day Ken, On Wed, 25 Mar 2009 00:13:48 -0700 (PDT) Ken-JP wrote: > > Say I have: > > > set.seed( 1 ) > > m <- matrix( runif(5^2), nrow=5, dimnames = > > list( c("A","B","C","D","E"), c("O","P","Q","R","S") ) ) > > m > O P Q R S > A 0.2655087 0.898389

Re: [R] Converting a Matrix to a Vector

2009-03-25 Thread Dimitris Rizopoulos
try this: set.seed(1) m <- matrix(runif(5^2), nrow = 5, dimnames = list(c("A","B","C","D","E"), c("O","P","Q","R","S"))) v <- c(m) names(v) <- paste(rownames(m), colnames(m)[col(m)], sep = ".") # or # names(v) <- outer(rownames(m), colnames(m), paste, sep = ".") v I hope it helps. Best, D

[R] Converting a Matrix to a Vector

2009-03-25 Thread Ken-JP
Say I have: > set.seed( 1 ) > m <- matrix( runif(5^2), nrow=5, dimnames = list( c("A","B","C","D","E"), > c("O","P","Q","R","S") ) ) > m O P Q R S A 0.2655087 0.89838968 0.2059746 0.4976992 0.9347052 B 0.3721239 0.94467527 0.1765568 0.7176185 0.2121425 C