Hi, You didnt provide an example dataset: set.seed(25) mycd<- data.frame(a_vol3=sample(1:20,20,replace=TRUE),a_vol4=sample(5:45,20,replace=TRUE),week=rep(1:4,each=5)) aggregate(a_vol3 ~ week , data = mycd, mean) aggregate(a_vol4 ~ week , data = mycd, mean) #The above two could be combined to: aggtr<-aggregate(. ~ week , data = mycd, mean) aggtr # week a_vol3 a_vol4 #1 1 9.4 12.8 #2 2 9.6 18.6 #3 3 12.2 23.8 #4 4 10.8 21.0 names(aggtr)[2:3]<- c("Target3 Total Volume/Week","Target4 Total Volume/Week") pdf("Karthick.pdf") mapply(plot, type="o",xlab="Week",ylab=gsub("(.*)\\s+(.*)","\\1 (\\2)",gsub("\\/.*|Total ","",names(aggtr)[2:3])),aggtr[,-1], main=names(aggtr)[2:3]) dev.off()
A.K. >I have code like this to group the data. How to create a single function to >test the target 3 and target 4? Please help me...... > >This is for target 3 >aggtr3<-aggregate(a_vol3 ~ week , data = mycd, mean) >aggtr3$week56<-c(1:57); aggtr3 >## Plot for Target3 Total volume / Week >tr3g<-plot(aggtr3$week56,aggtr3$a_vol3,type="o",xlab="Week",ylab="Target3 >(Volume)",xlim=c(0,60),ylim=c(0,3300)) >title(main="Target3 Total Volume / Week") > >This is for target 4 >aggtr4<-aggregate(a_vol4 ~ week , data = mycd, mean) >aggtr4$week56<-c(1:57) >aggtr4 >## Plot for Target4 Total volume / Week >tr4g<-plot(aggtr4$week56,aggtr4$a_vol4,type="o",xlab="Week",ylab="Target4 >(Volume)",xlim=c(0,60),ylim=c(0,3300)) >title(main="Target4 Total Volume / Week")
Karthick.pdf
Description: Adobe PDF document
______________________________________________ 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.