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

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -

c# - Populating Gridview inside Listview ItemTemplate On Web User Control from Code Behind -