Skip to content

Instantly share code, notes, and snippets.

@luisDVA
Created June 28, 2021 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luisDVA/20ad9b248b5f445d61ba02e2f3a2a591 to your computer and use it in GitHub Desktop.
Save luisDVA/20ad9b248b5f445d61ba02e2f3a2a591 to your computer and use it in GitHub Desktop.
## %######################################################%##
# #
#### 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