Skip to content

Instantly share code, notes, and snippets.

@mhoban
Created December 10, 2022 04:02
Show Gist options
  • Save mhoban/1274afe88d70e2e902e047bf886d6cbc to your computer and use it in GitHub Desktop.
Save mhoban/1274afe88d70e2e902e047bf886d6cbc to your computer and use it in GitHub Desktop.
library(tidyverse)
prefixes <- c("luke","Luke","lUKE","jim","Jim","sandy")
df <- tibble(
id = str_c(sample(prefixes,100,replace=T),stringi::stri_rand_strings(100,length=3)),
num = runif(100)
)
df <- df %>%
mutate(real_id = case_when(
str_detect(id,fixed("luke",ignore_case = TRUE)) ~ "luke",
str_detect(id,fixed("jim",ignore_case = TRUE)) ~ "jim",
TRUE ~ id
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment