Re: [R] Encoding Vector of Strings into Numerical Matrix

2009-01-05 Thread jim holtman
try this: > tags <- c("aaa", "ttt", "ccc", "gcc", "atn") > key <- c(a=0, c=1, g=2, t=3, n=0) > x <- t(sapply(strsplit(tags, ''), function(z) key[z])) > x a a a [1,] 0 0 0 [2,] 3 3 3 [3,] 1 1 1 [4,] 2 1 1 [5,] 0 3 0 On Mon, Jan 5, 2009 at 8:26 PM, Gundala Viswanath wrote: > Dear all, > > Gi

[R] Encoding Vector of Strings into Numerical Matrix

2009-01-05 Thread Gundala Viswanath
Dear all, Given such vector of array. tags <- c("aaa", "ttt", "ccc", "gcc", "atn") How can I obtain a matrix corresponding to it [,1] [,2] [,3] [1,]000 [2,]333 [3,]111 [4,]211 [5,]03 0 In principle: 1. Number of Column in matrix