[R] Code to fetch summary info from vector

David Winsemius dwinsemius at comcast.net
Tue Jan 15 19:17:34 CET 2013


On Jan 15, 2013, at 8:16 AM, Benjamin Gillespie wrote:

> Hi all,
>
> Thanks in advance for any help.
>
> I have a vector "b":
>
> b=c(1,1,1,2,3,4,3,2,1,1,1,1,1,2,3,4,5,4,3.5,3,2,1,1,1)
>
> Imagine b is river flow throughout time.
>
> I would like some code that will generate the following information:
>
> number of individual 'periods' where b>1 (= 2 in this case)
> period 1 length = 5, max = 4
> period 2 length = 8, max = 5
>
> I can't figure anything useful out.

Look at:

rle(b>1)
?rle

Should get you started.

-- 
David



David Winsemius, MD
Alameda, CA, USA



More information about the R-help mailing list