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

From: Hvidberg, Martin <mhv_at_dmu.dk>
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)
par(mfrow=c(1,2))

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



R-help_at_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. 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 https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive