Created
May 10, 2019 18:47
-
-
Save ateucher/81a2799e838a5a6fcd66cc6f20b14269 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
values <- runif(100) | |
# get runs where values > 0.75 (these are TRUE/FALSE) | |
runs <- rle(values > 0.75) | |
# Mask out the runs with lengths < 3 | |
runs$values[runs$lengths < 3] <- FALSE | |
# Get a vector of positions that meet the run criteria | |
masked <- inverse.rle(runs) | |
# The above gives TRUE/FALSE but can convert to TRUE/NA like the | |
# original solution | |
masked[!masked] <- NA | |
masked |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment