Created
December 14, 2018 23:06
-
-
Save MCMaurer/6d821fa5643cf0791a92d29672b8edf2 to your computer and use it in GitHub Desktop.
Find all the rows in a dataframe where a certain sequence appears at any point
This file contains 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
result <- matrix(nrow = nrow(mtcars), ncol = ncol(mtcars)-1) | |
for (i in 1:32) { | |
result[i,] <- rollapply(as.character(mtcars[i,]), 2, identical, c("1", "0")) | |
} | |
result2 <- vector(length = nrow(mtcars)) | |
for (i in 1:32) { | |
result2[i] <- TRUE %in% result[i,] | |
} | |
mtcars[result2,] | |
# for the rows where you DON'T have that sequence | |
mtcars[!result2,] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment