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
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
-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
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)
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:
: 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
, 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
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
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.
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
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
: [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
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
13 matches
Mail list logo