Re: [R] Converting Numerical Matrix to List of Strings

2009-01-11 Thread Douglas Bates
On Sun, Jan 11, 2009 at 9:38 AM, Gundala Viswanath wrote: > Hi all, > > Given a matrix: > >> mat > >[,1] [,2] [,3] > [1,]000 > [2,]333 > [3,]111 > [4,]211 > How can I convert it to a list of strings: >> desired_output > [1] "aaa" "ttt" "ccc" "g

Re: [R] Converting Numerical Matrix to List of Strings

2009-01-11 Thread Dimitris Rizopoulos
one way is the following: mat <- matrix(sample(0:3, 12, TRUE), 4, 3) strg <- c("a", "c", "g", "t") out <- strg[mat + 1] dim(out) <- dim(mat) apply(out, 1, paste, collapse = "") I hope it helps. Best, Dimitris Gundala Viswanath wrote: Hi all, Given a matrix: mat [,1] [,2] [,3] [1,]

Re: [R] Converting Numerical Matrix to List of Strings

2009-01-11 Thread jim holtman
try this: > mapping <- c('0'='a', '1'='c', '2'='g', '3'='t') > x <- matrix(sample(0:3, 30, TRUE), ncol=3) > x [,1] [,2] [,3] [1,]311 [2,]132 [3,]111 [4,]111 [5,]213 [6,]130 [7,]132 [8,]310

[R] Converting Numerical Matrix to List of Strings

2009-01-11 Thread Gundala Viswanath
Hi all, Given a matrix: > mat [,1] [,2] [,3] [1,]000 [2,]333 [3,]111 [4,]211 How can I convert it to a list of strings: > desired_output [1] "aaa" "ttt" "ccc" "gcc" In principle: 1. Number of Column in matrix = length of string (= 3) 2. N