[R] How to join data.frames and vectors of different length, in an inteligent way?

Hvidberg, Martin mhv at dmu.dk
Wed Jun 11 08:52:41 CEST 2008

Thanks Chuck

With your help I managed to write the code as I wanted it.
The result looks like this:

dafSamp <-
dafSamp$Ay <- ave(dafSamp$X2, dafSamp$X1, FUN=mean)
dafSamp$AA <- dafSamp$X2 * (mean(dafSamp$X2)/dafSamp$Ay)
dafSamp$My <- ave(dafSamp$X2, dafSamp$X1, FUN=median)
dafSamp$MA <- dafSamp$X2 * (median(dafSamp$X2)/dafSamp$My)
boxplot(AA~X1, data=dafSamp, main="Mean mode")
boxplot(MA~X1, data=dafSamp, main="Median mode")

It works like a dream.Thanks for you time

More information about the R-help mailing list