Re: [R] corresponding replicated el of one matrix in another matrix or vector

2014-07-23 Thread arun
Try: rbind(v2,unname(setNames(v1[,1],v1[,2])[v2]))    [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] v2 "a"  "a"  "a"  "a"  "a"  "c"  "c"  "c"  "c"  "c"   "c"   "c"   "c"   "c"     "1"  "1"  "1"  "1"  "1"  "3"  "3"  "3"  "3"  "3"   "3"   "3"   "3"   "3"     [,15] [,16]

Re: [R] corresponding replicated el of one matrix in another matrix or vector

2014-07-23 Thread Uwe Ligges
On 23.07.2014 22:15, carol white wrote: How to keep the same order of elements as v2 for the new matrix? Oh, come on, read the help files for the functions I provided! t(merge(data.frame(V2=v2), as.data.frame(v1), sort = FALSE)) Best, Uwe Ligges v3 [,1] [,2] [,3] [,4] [,5] [,6]

Re: [R] corresponding replicated el of one matrix in another matrix or vector

2014-07-23 Thread carol white
How to keep the same order of elements as v2 for the new matrix? > v3 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [1,] "a"  "a"  "a"  "a"  "a"  "c"  "c"  "c"  "c"  "c"   "c"   "c"   "c"   "c"  [2,] "1"  "1"  "1"  "1"  "1"  "3"  "3"  "3"  "3"  "3"   "3"   "3"  

Re: [R] corresponding replicated el of one matrix in another matrix or vector

2014-07-23 Thread Uwe Ligges
On 23.07.2014 21:16, carol white wrote: Hi, I have a matrix of unique elements (strings) like v1 and a vector which contains replicated values of the 2nd column of the first matrix. v1 = cbind(c("1","2","3"),c("a","b","c")) v2 = c(rep("a",5), rep("c",10), rep("b",3)) How can I add a column

[R] corresponding replicated el of one matrix in another matrix or vector

2014-07-23 Thread carol white
Hi, I have a matrix of unique elements (strings) like v1 and a vector which contains replicated values of the 2nd column of the first matrix. v1 = cbind(c("1","2","3"),c("a","b","c")) v2 = c(rep("a",5), rep("c",10), rep("b",3)) How can I add a column to v2 that contains the values of the first