r - Finding max run length of a particular value -
i have vector want analyze run length. ease of explanation, unfair coin flip so....100 "h" , "t"....but way more t's h's
i used
rle(sim) to run lengths.
i used
max(rle(sim)$length) to maximum run length of set. however, want value, h's. how that?
set.seed(100) coins <- sample(c("h", "t"), 1000, replace = true) rle_coins <- rle(coins) max(rle_coins$lengths[rle_coins$values == "h"]) use tapply grouped max:
tapply(rle_coins$lengths, rle_coins$values, max)
Comments
Post a Comment