[R] Reshape or Plyr?
arun
smartpink111 at yahoo.com
Sun Apr 21 23:38:56 CEST 2013
Hi Bruce,
From your second email, I think you solved the problem. But, still there is confusion due to the wordings.
res1<-mutate(ddply(dat1,.(SPEC_CODE),function(x) colSums(x[,-c(1:3,6)])),RA=10*(AI/Survey_Time))
res1
SPEC_CODE Survey_Time AI RA
1 Buzz 72.8 8 1.0989011
2 Eumspp 24.3 5 2.0576132
3 Frag 12.1 18 14.8760331
4 Molmol 12.1 1 0.8264463
5 Molspp 72.8 28 3.8461538
6 Myokea 12.2 1 0.8196721
7 Nocalb 24.3 10 4.1152263
8 Phyllo 36.4 4 1.0989011
9 Ptedav 36.4 3 0.8241758
10 Ptegym 36.4 6 1.6483516
11 Ptepar 36.4 9 2.4725275
12 Pteper 24.3 4 1.6460905
13 Rhotum 36.4 30 8.2417582
14 Sacbil 36.4 11 3.0219780
15 Saclep 36.4 32 8.7912088
#or
dat1$RA<-10*with(dat1,ave(AI,SPEC_CODE,FUN=sum))/with(dat1,ave(Survey_Time,SPEC_CODE,FUN=sum))
head(dat1)
# Location_name SPEC_CODE Start_Day Survey_Time AI Std_AI RA
#1 079-f2p1-Acetuna Buzz 2/14/2012 12.1 1 0.8264463 1.098901
#2 079-f2p1-Acetuna Buzz 2/14/2012 12.1 1 0.8264463 1.098901
#3 079-f2p1-Acetuna Eumspp 2/14/2012 12.1 1 0.8264463 2.057613
#4 079-f2p1-Acetuna Frag 2/14/2012 12.1 18 14.8760300 14.876033
#5 079-f2p1-Acetuna Molspp 2/14/2012 12.1 5 4.1322310 3.846154
#6 079-f2p1-Acetuna Molspp 2/14/2012 12.1 5 4.1322310 3.846154
________________________________
From: Bruce Miller <batsncats at gmail.com>
To: arun <smartpink111 at yahoo.com>
Sent: Sunday, April 21, 2013 4:19 PM
Subject: Re: [R] Reshape or Plyr?
Hi Arun,
This looks good; however the not quite correct yet.
Looks like the mutate option may be a good place to start.
Sorry I did not clearly explain this in my original query. For
adjustment by unit effort I need the "Base AI per hour" summed for
the location. Once I have that it can be standardized by 10
hours. An example for a single from your output
#9 Ptedav 079-f2p1-Acetuna 36.4 3 12.1333333 121.333333
Is not the correct way to determine AI per hour. So total survey hours for a 3 nights is 36.4 then the AI value is 3 so the AI per hour for Ptedav would be3/36.4 = .08241 then standardized for 10 hours of survey time would be 0.824175824.
Now I need to determine how to re-arrange your code to reflect the
Summed AI/Summed survey time.
res<- mutate(ddply(dat1,.(SPEC_CODE,Location_name),function(x) colSums(x[,-c(1:3,6)])),SumAIbySumST=Survey_Time/AI,Std.SumAIbySumST=10*SumAIbySumST)
Thanks again for your input and help.
Bruce
More information about the R-help
mailing list