[R] Adapting R code for different traps
Jonathan Daily
biomathjdaily at gmail.com
Thu Jun 9 20:03:01 CEST 2011
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 be a more elegant way to do it. If you want
to invest the time, there are some good dataset manipulation tools in
the packages reshape and plyr.
HTH,
Jon
On Thu, Jun 9, 2011 at 11:03 AM, bjmjarrett <bjmjarrett at gmail.com> wrote:
> 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)
>
> Trap collection.days.2 release.days days.since.last.release
> ACAP1 0 -266 -12 # this tells me that at day 0
> the last parasitoid release
>
> occurred 12 days beforehand, and so on...
> ACAP1 9 -259 -1
> ACAP1 28 -225 -20
> ACAP1 41 -216 -13
> ACAP1 77 -28 -36
> ACAP1 97 -12 -20
> ACAP1 106 0 -1
> ACAP1 125 8 -20
> ACAP1 146 28 -21
> ACAP1 168 41 -43
> ACAP1 195 77 -70
> ACAP1 217 97 -92
> ACAP1 259 105 -134
> ACAP1 288 125 -163
> ACAP1 311 288 -23
> ACAP1 337 311 -26
> ACAP1 378 337 -41
> ACAP1 400 378 -22
> ACAP1 440 400 -26
> ACAP1 464 414 -14
>
> The output I want is days.since.last.release for all of the traps I have.
>
> Thanks so much,
>
> Ben
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Adapting-R-code-for-different-traps-tp3585215p3585823.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>
--
===============================================
Jon Daily
Technician
===============================================
#!/usr/bin/env outside
# It's great, trust me.
More information about the R-help
mailing list