Re: [R] Code to fetch summary info from vector

2013-01-15 Thread David Winsemius
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 o

Re: [R] Code to fetch summary info from vector

2013-01-15 Thread Rui Barradas
Hello, Continuing Jessica's code, to get the maximum of each group just use 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) r <- rle(b > 1) groups <- rep(1:length(r$lengths),r$lengths) tapply(b, groups, FUN = max) # To get just the groups where b > 1, mx <- tapply(b, groups, FUN = m

Re: [R] Code to fetch summary info from vector

2013-01-15 Thread Benjamin Gillespie
runNumber[b<=1] <- NA > tapply(b, runNumber, max) 1 2 4 5 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of Benjamin Gillespie > Sent: Tuesday

Re: [R] Code to fetch summary info from vector

2013-01-15 Thread Jessica Streicher
Maybe rle can help a little here rle(b>1) Run Length Encoding lengths: int [1:5] 3 5 5 8 3 values : logi [1:5] FALSE TRUE FALSE TRUE FALSE r<-rle(b>1) r$lengths[r$values] [1] 5 8 # started for the maximum but need to go home now, sorry. Will continue tomorrow if noone else finishes it. g

Re: [R] Code to fetch summary info from vector

2013-01-15 Thread Jose Iparraguirre
al Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Benjamin Gillespie Sent: 15 January 2013 16:16 To: r-help@r-project.org Subject: [R] Code to fetch summary info from vector Hi all, Thanks in advance for any help. I

Re: [R] Code to fetch summary info from vector

2013-01-15 Thread William Dunlap
-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of Benjamin Gillespie > Sent: Tuesday, January 15, 2013 8:16 AM > To: r-help@r-project.org > Subject: [R] Code to fetch summary info from vector > > Hi all, > > Thanks in advance for any help. > > I have a

Re: [R] Code to fetch summary info from vector

2013-01-15 Thread Stephen Sefick
I don't know if I understand what you want. What are the periods? I suspect this is a time series. What have you tried that didn't work? kind regards, Stephen On 01/15/2013 10: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,

[R] Code to fetch summary info from vector

2013-01-15 Thread Benjamin Gillespie
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