I don't see how the data in the three column table you present is enough to 
produce the four column test.  Should the first table actually show repeated 
collar usage so that you can use the next incidence of the collar as the end 
date e.g
1 01/01/2013 
1 02/04/2013 

and so on?

Some actual data might be useful.  
 The easiest way to supply data  is to use the dput() function.  Example with 
your file named "testfile": 
dput(testfile) 
Then copy the output and paste into your email.  For large data sets, you can 
just supply a representative sample.  Usually,  dput(head(testfile, 100)) will 
be sufficient.  

Sorry I'm not more helpful


John Kane
Kingston ON Canada


> -----Original Message-----
> From: cat.e.co...@gmail.com
> Sent: Fri, 15 Mar 2013 12:46:13 +0800
> To: r-help@r-project.org
> Subject: [R] Reassign values based on multiple conditions
> 
> 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.

____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at 
http://www.inbox.com/smileys
Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most 
webmails

______________________________________________
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