[R] data frame manipulation - splitting monitoring interval and assigning stage

Jessi Brown jessilbrown at gmail.com
Wed Jun 25 19:29:55 CEST 2008


Hello, everyone.

I'm hoping to prevent myself from doing a lot of pointing and clicking
in Excel. I have a dataframe of bird nest check observations, in which
I know the date of the first check, the date of the second check (both
currently in Julian date format), the status of the nest at the second
check (alive or failed), and the date that the nest hatched (i.e.
changed from Incubation stages to Brood-rearing stage). Many nests
have more than one record, as there were several nest checks
throughout the duration of the nesting attempt.

What I want to do is assign a nest Stage variable, either Incubation
or Brood-rearing. It's very easy to do so when the second nest check
was before the hatch date (incubation), or when the first nest check
was after the hatch date (brood-rearing). But I can't figure out a
quick way to split the interval when it contained both incubation and
brood-rearing activities.

I'd like to go from:

Check1     Check2     HatchDate
101           121           110

to:

Check1     Check2     HatchDate    Stage
101           109          110               I
110           121          110               B

because even though the nest wasn't actually checked on the day of
hatching, we know that it transitioned to the next stage on hatch day.

There's other covariates as well as the unique nest ID which need to
be carried along too, just like HatchDate.

If anyone who is good at dataframe manipulation could suggest some
code to perform these actions, I would really appreciate it. Thanks in
advance.


cheers, Jessi Brown
Ecology, Evolution, and Conservation Biology
University of Nevada, Reno



More information about the R-help mailing list