[R] Create a function for test the data

arun smartpink111 at yahoo.com
Thu Apr 18 16:34:14 CEST 2013


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") 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Karthick.pdf
Type: application/pdf
Size: 5624 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130418/f45420c6/attachment.pdf>


More information about the R-help mailing list