Hi all,

I have a simple data frame of three columns - one of numbers (really a
categorical variable), one of dates and one of data.

Imagine:

collar date data
1 01/01/2013 x
2 02/01/2013 y
3 04/01/2013 z
4 04/01/2013 a
5 07/01/2013 b


The 'collar' is a GPS collar that's been worn by an animal for a certain
amount of time, and then may have been worn by a different animal after
changes when the batteries needed to be changed. When an animal was caught
and the collar battery needed to be changed, a whole new collar had to be
put on, as these animals (wild boar and red deer!) were not that easy to
catch. In order to follow the movements of each animal I now need to create
a new column that assigns the 'data' by animal rather than by collar. I
have a table of dates, e.g....

animal collar   start_date    end_date
     1              1  01/01/2013   03/01/2013
     1              5  04/01/2013   06/01/2013
     1              3  07/01/2013   09/01/2013
     2              2  01/01/2013   03/01/2013
     2              1  04/01/2013   06/01/2013

I have so far been able to make multi-conditional tests:

animal1test<- (date>=01/01/13 && date<=03/01/13)
animal1test2<- (date>=04/01/13 && date<=06/01/13)
animal2test<- (date>=04/01/13 && date<=06/01/13)

to use in an 'if else' formula:

 if(animal1test){
  collar[1]="animal1"
  } else if(animal1test2){
    collar[5]="animal1"
  }else if(animal2test)
    collar[1]="animal2"
    }else "NA"

As I'm sure you can see, this is completely inelegant, and also not working
for me! Any ideas on how to a achieve this?

Thanks SO much in advance,
Cat

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to