[R] Graphing a subset of data
Jim Lemon
drjimlemon at gmail.com
Tue Dec 1 11:28:52 CET 2015
Hi Alexandra,
I think you are going about this in an excessively difficult way. Here is a
rough example:
graphit<-function(x,var,type,subset=NA,...){
if(!is.na(subset[1])) x<-subset(x,subset)
do.call(type,list(x=x[[var]],...))
}
# assume that the data are measurements of penetration by crossbow bolts at
specified speeds
bolts<-data.frame(SPEED1=rep(1:3,each=30),
penetration=c(runif(30,10,15),runif(30,15,20),runif(30,20,25)))
# note the lazy way of adding arguments to the function call
graphit(bolts,"SPEED1",boxplot,main="Boxplot of SPEED1")
graphit(bolts,"penetration",boxplot,subset=bolts$SPEED1==3,
main="Boxplot of SPEED1 == 3")
graphit(bolts,"SPEED1",hist,main="Histogram of SPEED1")
Jim
[[alternative HTML version deleted]]
More information about the R-help
mailing list