s-news
[Top] [All Lists]

Re: behavioural sequence

To: s-news@lists.biostat.wustl.edu
Subject: Re: behavioural sequence
From: Achaz von Hardenberg <achaz@hermes.usherb.ca>
Date: Tue, 25 Feb 2003 17:27:03 +0100
In-reply-to: <3E5B754E.19747.156E484@localhost>
References: <se5b6f43.079@dlwcmail.dlwc.nsw.gov.au>
I wish to thank all people (12!) who suggested various different ways to solve my problem. All response I got seemed to work but I had to choose one, therefore I finally I followed the advice by James Holtman who wrote:

try 'rep'
rep(ifelse(your.data[,2]=="F", 1, 0), your.data[,3])
should do it.

I therefore created a new function which I called "binseq" like this:

> binseq<-function(x)
+ {data.frame(rep(ifelse(x[, 1] == "F", 1, 0), x[, 2]))}

A call to binseq like:

> seq1<-binseq(my.datafile)

provides me now with a new dataframe (seq1) exactly as I wished it!

I am starting to like this. :) I will therefore follow also Patrick Burn's advice and read his "A Guide for the Unwilling S User", committing to try to learn seriously S-programming...

Thanks again to everybody!

achaz


> >>> Achaz von Hardenberg <achaz@hermes.usherb.ca> 02/24/03 08:40pm >>>
> Hi S-Plusers!
>
> for a study in animal behaviour, I have a large number of files each
> with the following structure:
>
> 1  F  5
> 2  A  4
> 3  F  3
> 4  S  5
> 5  F  7
> 6  A  6
> 7 ...  ...
>
> The first column indicates the sequence, the second a behavioural
> pattern (F = Foraging, A= Alert, S= Sleep ...), the third is the time
> (in seconds) dedicated by the subject to each behaviour. I am looking
> for an S or R function to transform these files in a series of 1 and
> 0's with 1 for each second the animal was feeding and 0 for all other
> behaviours (A, S and others). The above sequence should therefore look
> like the following:
>
> 111110000111000001111111000000
>
> I think that this should (?) be quite straightforward to program, but
> I am a "0" in programming (and I guess also a bit lazy to start
> learning, also if I am aware I should!), so I am wondering if somebody
> outside there with more experience than me would be so kind to help me
> providing me with a code that would do it.
>
> Thanks a lot!
>
> achaz
>
>

Achaz von Hardenberg
_____________________
Département de Biologie,
Université de Sherbrooke
Sherbrooke, Québec
J1K 2R1 CANADA
____________________


<Prev in Thread] Current Thread [Next in Thread>