[R] replacing values in one vector with corresponding index from another vector

2011-10-19 Thread David Epstein
A quick question for the gurus... Given: a=c(58,73,100,40,70) b=c(40,70,73,100,58,70,70,58) How can I replace the elements of b with the corresponding index numbers from a that start at 1? All values in a are unique. So, I end up with: b=c(4,5,2,3,1,5,5,1) I believe I need to use one of the

Re: [R] replacing values in one vector with corresponding index from another vector

2011-10-19 Thread Sarah Goslee
How about a trick? b - as.numeric(factor(b, levels=a)) b [1] 4 5 2 3 1 5 5 1 On Wed, Oct 19, 2011 at 5:38 PM, David Epstein david...@umich.edu wrote: A quick question for the gurus... Given: a=c(58,73,100,40,70) b=c(40,70,73,100,58,70,70,58) How can I replace the elements of b with

Re: [R] replacing values in one vector with corresponding index from another vector

2011-10-19 Thread William Dunlap
Subject: [R] replacing values in one vector with corresponding index from another vector A quick question for the gurus... Given: a=c(58,73,100,40,70) b=c(40,70,73,100,58,70,70,58) How can I replace the elements of b with the corresponding index numbers from a that start at 1? All values

Re: [R] replacing values in one vector with corresponding index from another vector

2011-10-19 Thread David Epstein
thank you! that is straight forward. On Wed, 2011-10-19 at 22:37 +, William Dunlap wrote: match(b, a) [1] 4 5 2 3 1 5 5 1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide

Re: [R] replacing values in a vector

2010-08-18 Thread Greg Snow
Of Karen Kotschy Sent: Tuesday, August 17, 2010 4:37 PM To: Dimitris Rizopoulos Cc: r-help@r-project.org Subject: Re: [R] replacing values in a vector Thanks so much to all those who suggested solutions! You guys are wonderful! I went with Dimitris' suggestion in the end. Regards Karen

[R] replacing values in a vector

2010-08-17 Thread Karen Kotschy
Dear helpRs Does anyone have an elegant way of doing the following: For a given numeric vector, e.g. vec - c(3,2,6,4,7) Create a series of vectors where all but 1 of the values are replaced by 0's, e.g. vec.a - c(3,0,0,0,0) vec.b - c(0,2,0,0,0) vec.c - c(0,0,6,0,0) vec.d - c(0,0,0,4,0)

Re: [R] replacing values in a vector

2010-08-17 Thread Jorge Ivan Velez
Hi Karen, Try this: vec - c(3,2,6,4,7) res - diag(vec) k - length(vect) for(i in 1:k) assign(paste('vec', letters[i], sep = '.'), res[i,]) vec.a # [1] 3 0 0 0 0 vec.b # [1] 0 2 0 0 0 HTH, Jorge On Tue, Aug 17, 2010 at 6:57 AM, Karen Kotschy wrote: Dear helpRs Does anyone have an elegant

Re: [R] replacing values in a vector

2010-08-17 Thread Henrique Dallazuanna
Try this: mapply(function(x, y)assign(x, y, envir = globalenv()), sprintf('vec.%s', letters[1:length(vec)]), split(diag(vec), 1:length(vec))) On Tue, Aug 17, 2010 at 7:57 AM, Karen Kotschy ka...@sevenc.co.za wrote: Dear helpRs Does anyone have an elegant way of doing the following: For a

Re: [R] replacing values in a vector

2010-08-17 Thread Charles Roosen
] replacing values in a vector Dear helpRs Does anyone have an elegant way of doing the following: For a given numeric vector, e.g. vec - c(3,2,6,4,7) Create a series of vectors where all but 1 of the values are replaced by 0's, e.g. vec.a - c(3,0,0,0,0) vec.b - c(0,2,0,0,0) vec.c - c(0,0,6,0,0

Re: [R] replacing values in a vector

2010-08-17 Thread Dimitris Rizopoulos
try this: vec - c(3,2,6,4,7) n - length(vec) for(i in seq_along(vec)){ r - numeric(n) r[i] - vec[i] assign(paste(vec., letters[i], sep = ), r) } I hope it helps. Best, Dimitris On 8/17/2010 12:57 PM, Karen Kotschy wrote: Dear helpRs Does anyone have an elegant way of doing

Re: [R] replacing values in a vector

2010-08-17 Thread Karen Kotschy
Thanks so much to all those who suggested solutions! You guys are wonderful! I went with Dimitris' suggestion in the end. Regards Karen On Tue 17Aug10, Dimitris Rizopoulos wrote: try this: vec - c(3,2,6,4,7) n - length(vec) for(i in seq_along(vec)){ r - numeric(n) r[i] -

[R] replacing values in a vector

2008-11-06 Thread Iain Gallagher
Hello list. I have a vector of values: eg head(diff_mirs_list) [1] hsa-miR-26b hsa-miR-26b hsa-miR-23a hsa-miR-27b hsa-miR-29a [6] hsa-miR-29b and I would like to conditionally replace each value in this vector with a number defined in a dataframe: fc Probe ave.fc 1  

Re: [R] replacing values in a vector

2008-11-06 Thread Rolf Turner
Boy are you confused. This has nothing at all to do with substitution. Instead do test - with(fc,ave.fc[match(diff_mirs_list,Probe)]) cheers, Rolf Turner On 7/11/2008, at 11:46 AM, Iain Gallagher wrote: Hello list. I have a vector of values: eg