Created
June 28, 2021 20:53
-
-
Save luisDVA/20ad9b248b5f445d61ba02e2f3a2a591 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
## %######################################################%## | |
# # | |
#### Regex for data cleaning 1 - your turn #### | |
# # | |
## %######################################################%## | |
# After running the code below: | |
library(ggplot2) | |
library(dplyr) | |
library(stringr) | |
msleep %>% | |
select(name,genus) %>% | |
filter(str_detect(string = name,pattern = "rat")) | |
# How can we exclude muskrats from the matches? | |
# exclude muskrats from matches in the 'name' variable -------------------- | |
# Look at resulting object, second row includes the Round-tailed muskrat | |
msleep %>% | |
select(name, genus) %>% | |
filter(str_detect(string = name, pattern = "rat")) | |
# modify the regexp that goes into the 'pattern' argument | |
# note the shorthand word boundary | |
msleep %>% | |
select(name, genus) %>% | |
filter(str_detect(string = name, pattern = "\\brat")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment