Re: [R] numbering consecutive rows based on length criteria

2015-03-02 Thread Thierry Onkelinx
Dear Eric, Here is a solution using the plyr package. library(plyr) dat$flg <- dat$wRes.Q>dat$noRes.Q dat$group <- cumsum(c(0, abs(diff(dat$flg ddply(dat, "group", function(x){ if(x$flg[1] && nrow(x) >= 5){ x$plygn <- seq_along(x$group) } else { x$plygn <- NA } x }) Best rega

Re: [R] numbering consecutive rows based on length criteria

2015-03-02 Thread Marc Schwartz
On Mar 2, 2015, at 11:43 AM, Morway, Eric wrote: > > Using this dataset: > > dat <- read.table(textConnection("daynoRes.QwRes.Q > 1 237074.41 215409.41 > 2 2336240.20 164835.16 > 3 84855.42 357062.72 > 4 76993.48 386326.78 > 5 73489.47 307144.09 > 6 70246.96 75885.75 > 7 6963

[R] numbering consecutive rows based on length criteria

2015-03-02 Thread Morway, Eric
Using this dataset: dat <- read.table(textConnection("daynoRes.QwRes.Q 1 237074.41 215409.41 2 2336240.20 164835.16 3 84855.42 357062.72 4 76993.48 386326.78 5 73489.47 307144.09 6 70246.96 75885.75 7 69630.09 74054.33 8 66714.78 70071.80 9 122296.90 66579.08 10