Re: [R] Adapting R code for different traps

2011-06-09 Thread Jonathan Daily
OK, Assume all your trap names are stored in a vector trap.names. Does: sapply(trap.names, FUN = function(x) { tmp. <- outer(release.days[Trap==x],collection.days.2[Trap==x],'-') tmp <- ifelse(temp.ACAP1>=0,NA,temp.ACAP1) return(apply(temp.ACAP1,2,max,na.rm=TRUE)) } ) Work? I feel there has to b

Re: [R] Adapting R code for different traps

2011-06-09 Thread bjmjarrett
Hi Jon, Sorry about the lack of information. I'll give the data from one of my traps: (nb. all of the data for each trap is referenced to the start day of the trap. ie ACAP1 started collecting at day 0 but parasitoid releases occurred 266, 259, 225 etc days before collecting took place) Trapc

Re: [R] Adapting R code for different traps

2011-06-09 Thread bjmjarrett
The below works for one trap. Surely there is a quick way to scale it to all of the traps? > temp.ACAP1<-outer(release.days[Trap=="ACAP1"],collection.days.2[Trap=="ACAP1"],'-') > temp.ACAP1<-ifelse(temp.ACAP1>=0,NA,temp.ACAP1) > diff.ACAP1<-apply(temp.ACAP1,2,max,na.rm=TRUE) Thanks Ben -- View

Re: [R] Adapting R code for different traps

2011-06-09 Thread Jonathan Daily
Hi Ben, Unfortunately, I left the usb cable for my crystal ball at home, and thus have no idea how your data is organized. Could you post an example along with what you expect the output to be? Jon On Thu, Jun 9, 2011 at 7:22 AM, bjmjarrett wrote: > Hi all, > > My code: > >> temp<-outer(release

[R] Adapting R code for different traps

2011-06-09 Thread bjmjarrett
Hi all, My code: > temp<-outer(release.days,collection.days,'-') > temp<-ifelse(temp>=0,NA,temp) > release.diff<-apply(temp,2,max,na.rm=TRUE) works for one trap and does what I want. That is, it determines the time difference between the collection date of a trap and date of parasitoid release i