Marit1
April 6, 2021, 10:59am
1
Hello, I am wondering whether the word 'doctor' in my script is capital sensitive or not.
And if every variable that contains the word ' doctor' will be categorized as 23?
research <- work_sector_new %>%
mutate(
label = case_when(
str_detect(work_sector, "doctor") ~ "23",
FJCC
April 6, 2021, 12:18pm
2
Here are examples of searching with and without case insensitivity using the tag (?i).
library(dplyr)
library(stringr)
work_sector_new <- data.frame(work_sector=c("a doctor", "The Doctor", "mechanic",
"doctorate"))
#Case sensitive version
work_sector_new %>%
mutate(
label = case_when(
str_detect(work_sector, "doctor") ~ "23"))
work_sector label
1 a doctor 23
2 The Doctor <NA>
3 mechanic <NA>
4 doctorate 23
#Case insensitive version
work_sector_new %>%
mutate(
label = case_when(
str_detect(work_sector, "(?i)doctor") ~ "23"))
work_sector label
1 a doctor 23
2 The Doctor 23
3 mechanic <NA>
4 doctorate 23
1 Like
system
Closed
April 27, 2021, 12:18pm
3
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.