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

From: Hvidberg, Martin <>
Date: Wed, 11 Jun 2008 08:52:41 +0200

Thanks Chuck

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

dafSamp <-
data.frame(cbind(c(1972,1984,1969,1976,1999,1996,1976,1984,1976),c(117,7 3,92,113,80,78,98,106,99)))

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 Martin mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed 11 Jun 2008 - 08:36:21 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 11 Jun 2008 - 09:30:38 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive