Re: [R] help: program efficiency

2010-11-27 Thread Romain Francois
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 runs of duplicated values, not all duplicated values) the following is pretty quick nodup3- function (t) { t + (sequence(rle(t)$lengths) - 1

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 don't

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 runs of duplicated values, not all duplicated

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 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:

Re: [R] help: program efficiency

2010-11-26 Thread Romain Francois
: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of randomcz 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

Re: [R] help: program efficiency

2010-11-26 Thread Romain Francois
, 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 runs of duplicated values, not all duplicated values) the following is pretty quick nodup3- function (t) { t + (sequence(rle(t

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) { swn - seq(from = 0, to = (0 + 0.01*length(x

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.

[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

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 value

Re: [R] help: program efficiency

2010-11-25 Thread William Dunlap
: [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,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

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 example, the original vector would