Re: [R] Identify duplicate numbers and to increase a value

2011-01-20 Thread Gabor Grothendieck
On Thu, Jan 20, 2011 at 10:12 AM, Ortiz, John wrote: > Hi everybody. > > I want to identify duplicate numbers and to increase a value of 0.01 for each > time that it is duplicated. > > Example: > x=c(1,2,3,5,6,2,8,9,2,2) > > I want to do this: > > 1 > 2 + 0.01 > 3 > 5 > 6 > 2 + 0.02 > 8 > 9 > 2 +

Re: [R] Identify duplicate numbers and to increase a value

2011-01-20 Thread James Lawrence
Hello John, If many numbers are duplicated, then one way is to coerce to a factor and use the levels() function. For instance: x <- c(1,1,2,2,2,3,3,4,1,1,2,4) X <- factor(x) for (i in levels(X)) { loc <- (X==i); len = length(loc) x[loc] <- x[loc] + 0.01 * (1:len) } x [1] 1.01 1.

Re: [R] Identify duplicate numbers and to increase a value

2011-01-20 Thread Henrique Dallazuanna
Try this: replace(x + ave(x, x, FUN = seq) * .01, !(duplicated(x) | duplicated(x, fromLast = TRUE)), x) On Thu, Jan 20, 2011 at 1:12 PM, Ortiz, John wrote: > Hi everybody. > > I want to identify duplicate numbers and to increase a value of 0.01 for > each time that it is duplicated. > > Example

Re: [R] Identify duplicate numbers and to increase a value

2011-01-20 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Ortiz, John > Sent: Thursday, January 20, 2011 7:13 AM > To: r-help@r-project.org > Subject: [R] Identify duplicate numbers and to increase a value > > H

Re: [R] Identify duplicate numbers and to increase a value

2011-01-20 Thread Joshua Wiley
Hi John, If you only have one duplicated number (e.g., just 2), then this will work: x <- c(1,2,3,5,6,2,8,9,2,2) xd <- duplicated(x) x[xd] <- x[xd] + seq(sum(xd))/100 x otherwise, I think a different framework than duplicated() will be necessary, because it will matter not just if the number is

Re: [R] Identify duplicate numbers and to increase a value

2011-01-20 Thread Moritz Grenke
ards Moritz Moritz Grenke http://www.360mix.de -Ursprüngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von Ortiz, John Gesendet: Donnerstag, 20. Januar 2011 16:13 An: r-help@r-project.org Betreff: [R] Identify duplicate numbers and

[R] Identify duplicate numbers and to increase a value

2011-01-20 Thread Ortiz, John
Hi everybody. I want to identify duplicate numbers and to increase a value of 0.01 for each time that it is duplicated. Example: x=c(1,2,3,5,6,2,8,9,2,2) I want to do this: 1 2 + 0.01 3 5 6 2 + 0.02 8 9 2 + 0.03 2 + 0.04 I am trying to get something like this: 1 2.01 3 5 6 2.02 8 9 2.03 2