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

From: Jessi Brown <jessilbrown_at_gmail.com>
Date: Wed, 25 Jun 2008 13:29:55 -0400


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



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. Received on Wed 25 Jun 2008 - 17:35:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 26 Jun 2008 - 01:31:02 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive