[R] Function to do multiple named lookups faster?
David Reiss
dreiss.isb at gmail.com
Tue Feb 27 19:43:26 CET 2007
Hi,
I apologize if this topic has been discussed - I could not figure out
a good search phrase for this question.
I have a named vector x, with multiple (duplicate) names, and I would
like to obtain a (shorter) vector with non-duplicate names in which
the values are the means of the values of the duplicated indexes in x.
My best (fastest) solution to this was this code:
nms <- names( x )
x.uniq <- sapply( unique( nms ), function( i ) mean( subtracted[ nms == i ] ) )
However, this takes forever on my beefy Mac Pro. Is there a faster way
to this using pre-written functions in R?
Thanks a lot for any advice.
-David
More information about the R-help
mailing list