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
## %######################################################%## | |
# # | |
#### 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