[R] Splitting Data by Row

Jim Lemon jim at bitwrit.com.au
Sat Jun 20 12:19:02 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) 
>
> 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!
>
>   
Hi Ross,
The brkdn function in the prettyR package does this, and I am currently 
working on a more efficient version of this that will drive an improved 
hierobarp function in the plotrix package.

Jim




More information about the R-help mailing list