Skip to content
Prev 315357 / 398503 Next

Code to fetch summary info from vector

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 = max)
mx[mx > 1]

# And you can combine both like in

cbind(length = r$lengths[r$values], max = mx[mx > 1])


Hope this helps,

Rui Barradas
Em 15-01-2013 16:57, Jessica Streicher escreveu: