Skip to content

Reshape or Plyr solution

1 message · Bruce Miller

#
Hi all,

I had several replies that provided a solution to my previous query.

Using plyr it seems to work (Thanks Dennis Murphy and Arun)
library(plyr)
ddply(DF, .(SPEC_CODE), mutate, RA = 10 * sum(AI)/sum(Time))

This one nearly works just need to invert the SumAI and Sum Survey time 
so that SumAI/SumTime provides the correct answer.

res<- mutate(ddply(dat1,.(SPEC_CODE,Location_name),function(x) colSums(x[,-c(1:3,6)])),SumAIbySumST=Survey_Time/AI,Std.SumAIbySumST=10*SumAIbySumST)

Tnx all for the help,

Bruce