Re: [R] help: program efficiency

2010-11-27 Thread Mike Marchywka
> > So in this example, it seems more efficient to sort first and use the > algorithm assuming that the data is sorted. > > There is probably a way to be smarter in nodup_cpp where the bottleneck > is likely to be related to map::find. If you just use a hash table, std::map should work too, I d

Re: [R] help: program efficiency

2010-11-27 Thread Romain Francois
) )[oo] } ) utilisateur système écoulé 0.251 0.011 0.262 > system.time( { oo <- order(order(x)) ; nodup4( sort( x ) )[oo] } ) utilisateur système écoulé 0.287 0.006 0.294 Romain Le 26/11/10 20:01, William Dunlap a écrit : -Original Message- From: William Dunlap Sent: Thursday, Nov

Re: [R] help: program efficiency

2010-11-26 Thread randomcz
Thanks guys, the "rle" function works pretty well. Thank you all for the efforts. Zheng -- View this message in context: http://r.789695.n4.nabble.com/help-program-efficiency-tp3059079p3061103.html Sent from the R help mailing list archive at Nabble.com. ___

Re: [R] help: program efficiency

2010-11-26 Thread Mike Marchywka
> Date: Fri, 26 Nov 2010 11:25:26 -0800 > From: roman.lust...@gmail.com > To: r-help@r-project.org > Subject: Re: [R] help: program efficiency > > > Oops, tiny mistake. Try > > lapply(X = b, FUN = function(x) { >

Re: [R] help: program efficiency

2010-11-26 Thread Romain Francois
7 0.006 0.294 Romain Le 26/11/10 20:01, William Dunlap a écrit : -Original Message- From: William Dunlap Sent: Thursday, November 25, 2010 9:31 AM To: 'randomcz'; r-help@r-project.org Subject: RE: [R] help: program efficiency If the input vector t is known to be

Re: [R] help: program efficiency

2010-11-26 Thread Romain Francois
r: > x <- c( 2, 1, 1, 2 ) > nodup4( sort( x ) ) [1] 1.00 1.01 2.00 2.01 > nodup_cpp( x ) [1] 2.00 1.00 1.01 2.01 Romain Le 26/11/10 20:01, William Dunlap a écrit : -Original Message- From: William Dunlap Sent: Thursday, November 25, 2010 9:31 AM To: 'randomcz'; r-he

Re: [R] help: program efficiency

2010-11-26 Thread Roman Luštrik
Oops, tiny mistake. Try lapply(X = b, FUN = function(x) { swn <- seq(from = 0, to = (0 + 0.01*length(x))-0.01, by = 0.01) out <- x + swn return(out) }) -- View this message in context: http://r.789695.n4.na

Re: [R] help: program efficiency

2010-11-26 Thread Roman Luštrik
See if this works for you. a <- c(2,1,1,3,3,3,4) a.fac <- as.factor(a) b <- split(a, f = a.fac) system.time(lapply(X = b, FUN = function(x) { swn <- seq(from = 0, to = 0 + 0.01*length(x), by = 0.01) out <- x + swn return(out)

Re: [R] help: program efficiency

2010-11-26 Thread William Dunlap
> -Original Message- > From: William Dunlap > Sent: Thursday, November 25, 2010 9:31 AM > To: 'randomcz'; r-help@r-project.org > Subject: RE: [R] help: program efficiency > > If the input vector t is known to be ordered > (or if you only care about ru

Re: [R] help: program efficiency

2010-11-25 Thread Mike Marchywka
> Date: Thu, 25 Nov 2010 06:49:19 -0800 > From: rando...@gmail.com > To: r-help@r-project.org > Subject: [R] help: program efficiency > > > hey guys, > > I am working on a function to make a duplicated value unique. For exa

Re: [R] help: program efficiency

2010-11-25 Thread William Dunlap
cz > Sent: Thursday, November 25, 2010 6:49 AM > To: r-help@r-project.org > Subject: [R] help: program efficiency > > > hey guys, > > I am working on a function to make a duplicated value unique. > For example, > the original vector would be like : a = c(2,1,

Re: [R] help: program efficiency

2010-11-25 Thread Dimitris Rizopoulos
one way is the following: a <- c(2,1,1,3,3,3,4) d <- unlist(sapply(rle(a)$length, function (x) if (x > 1) seq(0.01, by = 0.01, len = x) else 0)) a + d I hope it helps. Best, Dimitris On 11/25/2010 3:49 PM, randomcz wrote: hey guys, I am working on a function to make a duplicated val

[R] help: program efficiency

2010-11-25 Thread randomcz
hey guys, I am working on a function to make a duplicated value unique. For example, the original vector would be like : a = c(2,1,1,3,3,3,4) I'll like to transform it into: a.nodup = 2, 1.01, 1.02, 3.01, 3.02, 3.03, 4 basically, find the duplicates and assign a unique value by adding a small amo