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@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