Hi,

This is probably really obvious, by I can't seem to find anything on it.

Is there a fast version of ave for when the data is already sorted in terms of the factor, or if the breaks are already known?

Basically, I have:
X = 0.1, 0.2, 0.32, 0.32, 0.4, 0.56, 0.56, 0.7...
Y = 223, 434, 343, 544, 231.... etc
of the same, admittedly large length.

Now note that some of the values of X are repeated. What I want to do is, for those X that are repeated, take the corresponding values of Y and change them to the average for that particular X.

So, ave(Y,X) will work. But it's very slow, and certainly not suited to my problem, where Y changes and X stays the same and I need to repeatedly recalculate the averaging of Y. Ave also does not take take advantage of the sorting of the data.

So, is there an alternative? (Presumeably avoiding loops.)

Thanks,

Zhou Fang

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to