Hi Bruce, This could be also done by: dat1<- read.csv("Sample_all_3_locations.csv",header=TRUE,stringsAsFactors=FALSE,sep=",") library(plyr) res1<-ddply(unique(dat1[,c(1,3:4)]),.(Location_name),summarize,Survey_Time=sum(Survey_Time)) #changed here res1 # Location_name Survey_Time #1 1_f3p1_La_Campana 46.4 #2 2_f4p1_La_Campana 69.5 #3 79_f2p1_Acetuna 36.4
#The rest as mentioned before. res2<-ddply(dat1,.(Location_name,SPEC_CODE),summarize, AI=sum(AI)) Final<- mutate(join(res1,res2),RA=10*(AI/Survey_Time)) A.K. ----- Original Message ----- From: Bruce Miller <batsnc...@gmail.com> To: arun <smartpink...@yahoo.com> Cc: Sent: Monday, April 22, 2013 12:55 PM Subject: Re: More Hi Arun, My last message overlapped yours. YES... that seems correct. Now if I can get this to work with teh entire data set all is be great. Thanks again for your valuable time and help. Bruce On 4/22/2013 12:16 PM, arun wrote: > Hi Bruce, > > From your excel sheets, it looks like for the step1, you were just taking >only the "Survey Time" of the first rows of unique Start_Day for each >Location_name. > > Step2 results looks the same as "res2" > If this is the case: > > dat1<- > read.csv("Sample_all_3_locations.csv",header=TRUE,stringsAsFactors=FALSE,sep=",") > library(plyr) > > res1<-ddply(aggregate(Survey_Time~Location_name+Start_Day,data=dat1,function(x) > head(x,1)),.(Location_name),summarize,Survey_Time=sum(Survey_Time)) > res1 > # Location_name Survey_Time > #1 1_f3p1_La_Campana 46.4 > #2 2_f4p1_La_Campana 69.5 > #3 79_f2p1_Acetuna 36.4 > > res2<-ddply(dat1,.(Location_name,SPEC_CODE),summarize, AI=sum(AI)) > > Final<- mutate(join(res1,res2),RA=10*(AI/Survey_Time)) > head(Final) > # Location_name Survey_Time SPEC_CODE AI RA > #1 1_f3p1_La_Campana 46.4 Buzz 20 4.3103448 > #2 1_f3p1_La_Campana 46.4 Cencen 20 4.3103448 > #3 1_f3p1_La_Campana 46.4 Eptfur 215 46.3362069 > #4 1_f3p1_La_Campana 46.4 Frag 3 0.6465517 > #5 1_f3p1_La_Campana 46.4 Molspp 22 4.7413793 > #6 1_f3p1_La_Campana 46.4 Myoele 1 0.2155172 > dim(Final) > #[1] 44 5 > A.K. > > > ----- Original Message ----- > From: Bruce Miller <batsnc...@gmail.com> > To: arun <smartpink...@yahoo.com> > Cc: > Sent: Monday, April 22, 2013 11:32 AM > Subject: Re: More > > Arun, > > Attached are two Excel sheets that I manually did what I am hoping I can > automate in R for the larger data sets. > > These use the same 3 locations and data I sent earlier. > > Step 1 sums the total survey time for each location then step 2 sums the AI > values for he SPEC_CODE by location. > > Then the calculation of Summed AI value/Summed Survey time can be completed > for each location and SPEC_Code. > Hopefully this clarifies it more. > > Bruce > > -- Bruce W. Miller, Ph.D. > Conservation Ecologist > Neotropical Bat Projects > > > office details > 11384 Alpine Road > Stanwood, Mi. 49346 > Phone (231) 679-6059 > -- Bruce W. Miller, Ph.D. Conservation Ecologist Neotropical Bat Projects office details 11384 Alpine Road Stanwood, Mi. 49346 Phone (231) 679-6059 ______________________________________________ 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.