[R] Odp: Fwd: 'for Loop'

Petr PIKAL petr.pikal at precheza.cz
Wed Apr 1 17:41:24 CEST 2009


Hi

r-help-bounces at r-project.org napsal dne 01.04.2009 11:16:26:

> Hello,
> 
> A nice guy call Jun Shen was helping me out with this, but I require a 
bit 
> more help. Below is my data set or list called 'test'. I'm trying to 
calculate
> the %RSD for each pair of index and keep it in cronological order if you 
can 
> imagine a 3rd column with 'date' beside index.
> 
>     Result Index
> 1   0.2901    17
> 2   0.2928    17
> 3   0.2913    18
> 4   0.2893    18
> 5   0.3526     9
> 6   0.3316     9
> 7   0.3492    10
> 8   0.3467    10
> 9   0.3385    11
> 10  0.3341    11
> 11  0.3449    12
> 12  0.3406    12
> 13  0.3690    13
> 14  0.3327    13
> 15  0.3324    14
> 16  0.3245    14
> 17  0.3245    15
> 18  0.3229    15
> 19  0.3331    16
> 20  0.3208    16
> 
> 
> now this bit of programming works for it how ever it puts the mean of my 
index
> back into numeric order.
> 
> aggregate(test[1],test[2],mean)->inter
> names(inter)[2]='mean'
> merge(test,inter,all=T)->inter2
> inter2$RSV=inter2$Result/inter2$mean
> 

?ave was also recommended and for your case it is strightforward

test$mean<-ave(test$Result, test$Index)
test$RSV<-test$Result/test$mean

Regards
Petr

> Would anyone know away around this so I could keep the data in 
cronological order?
> 
> Kind Regards,
> Al
> 
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.




More information about the R-help mailing list