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

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -