Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- combn(50, 5, simplify=FALSE) %>% # Get all (sorted) combinations of 5 choices from 1 to 50, i.e. 5,20,21,22,45
- lapply(diff) %>% # get the differences between consecutive values, i.e. 15,1,1,13
- lapply(rle) %>% # convert into runs of values, ie (1x15), (2x1s), (1x13)
- sapply(
- # do any of them give a run of 2 or more 1s?
- # (indicating 3 or more values with difference 1)
- function(x) any(x$lengths[x$values==1] >= 2)
- ) %>%
- mean # get the average value, which gives us the proportion (out of 1) of values that returned TRUE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement