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
Thanks everyone, I've used the code Will supplied - this worked well. Thanks to all the others who contributed. Ben Gillespie Research Postgraduate School of Geography University of Leeds Leeds LS2 9JT Tel: +44(0)113 34 33345 Mob: +44(0)770 868 7641 http://www.geog.leeds.ac.uk/ ___

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
Hi Ben I'm not sure whether I understood correctly, but is it something like this? > sum(ifelse(b==2,1,0)) [1] 4 > sum(ifelse(b==3,1,0)) [1] 4 > sum(ifelse(b>=2,1,0)) [1] 13 > sum(ifelse(b>2,1,0)) [1] 9 Etc... José José Iparraguirre Chief Economist Age UK -Original Message- From: r-h

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

2013-01-15 Thread William Dunlap
I don't completely understand the question, but if you are looking for the lengths of the runs of values greater than 1 then rle() would help: > 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) > r Run Length Encoding lengths: int [1:5] 3 5 5 8 3 values : l

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,