[R] help: program efficiency
randomcz
randomcz at gmail.com
Thu Nov 25 15:49:19 CET 2010
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
amount and keep it in order.
I come up with the following codes, but it runs slow if t is large. Is there
a better way to do it?
nodup = function(t)
{
t.index=0
t.dup=duplicated(t)
for (i in 2:length(t))
{
if (t.dup[i]==T)
t.index=t.index+0.01
else t.index=0
t[i]=t[i]+t.index
}
return(t)
}
--
View this message in context: http://r.789695.n4.nabble.com/help-program-efficiency-tp3059079p3059079.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list