Other option:

which(!diff(as.numeric(factor(x, levels = c("MagDwn", "Resp")))))[1]

On Fri, Jan 14, 2011 at 10:12 AM, Henrique Dallazuanna <www...@gmail.com>wrote:

> Try this:
>
>  which(x %in% c("MagDwn", "Resp"))[2]
>
>
> On Fri, Jan 14, 2011 at 7:22 AM, surreyj <surreyjack...@gmail.com> wrote:
>
>>
>> Hello everyone,
>>
>> I am currently working with some data where I need to select the first
>> occurrence of a value after the occurrence of another value.
>>
>> The data has two columns, one with a time and one with occurence of
>> certain
>> events.
>>
>>
>> The column of data I want to select from looks like this (and each of
>> these
>> events have a corresponding time in another column).
>>
>> Stat71
>> OutMag
>> FirstResp
>> InMag
>> MagUp
>> OutMag
>> MagDwn
>> Resp
>> Resp
>> Resp
>> InMag
>> MagUp
>> OutMag
>> InMag
>> OutMag
>> InMag
>> OutMag
>> InMag
>> OutMag
>> InMag
>> MagDwn
>> OutMag
>> Resp
>> MagUp
>> InMag
>> MagDwn
>> OutMag
>> Resp
>> MagUp
>>
>>
>> Using "which" I have selected all the individual occurrences of each event
>> and created variables with the time of said events within them which I
>> used
>> to calculate differences in time etc for analysis.
>>
>> But now I am faced with the issue that I need to select only the first
>> "Resp" that occurs after a "MagDwn" so that I can calculate the
>> differences
>> in time between these two events.
>>
>> Any help would be appreciated, usually I just read these forums and try
>> and
>> figure out problems for myself but this is for my masters and I'm running
>> out of time to get it finished :)
>>
>> Thanks
>>
>> Surrey
>>
>> --
>> View this message in context:
>> http://r.789695.n4.nabble.com/Selecting-the-first-occurrence-of-a-value-after-an-occurrence-of-a-different-value-tp3217340p3217340.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> 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.
>>
>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[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