[R] Splitting Data by Row

Uwe Ligges ligges at statistik.tu-dortmund.de
Fri Jun 19 16:48:48 CEST 2009



Ross Culloch wrote:
> Hello fellow R users!
> 
> I wonder if someone can help with what i think should be a simple question
> but i can't seem to find the answer or work it out.
> 
> My data set is as such:
> 
> Day Time ID Behaviour
> 1      9     A1     2
> 1      10    A2     3
> ..      ..    ..       ..
> 4      10   A1     10
> 4      11   A2      1
> ..      ..    ..      ..
> 30     1    B1     14
> 30     2    C3     4
> 
> So basically i have data for several days, for several times, for several
> IDs and for several Behaviours
> 
> What i want to do is get an activity budget for ID from these data, e.g:
> 
> data <- tapply(Behaviour,list(ID,Behaviour),length) 


What about adding Day or Time to the list?
Or maybe I haven't got your question.

Uwe Ligges


> This will give me a count of the number of times an ID does a certain
> behaviour for all the data, which is great - but i want to work out seasonal
> and diurnal activity budgets too, therefore i need to break the data down
> not just by ID but by day and time, too - I've searched on here and found
> nothing i could adapt to my data - it may be that i can't see quite how the
> code would work and i've overlooked something of importance!
> 
> If anyone can point me in the right direction i'd be most grateful!
> 
> Cheers,
> 
> Ross




More information about the R-help mailing list