i have added a line to the pipe operations
here we go
library(tidyverse)
data <- tibble(DIED = c("Y","", "N","","","" , "", " "),
SYMPTOM = c("right side of epiglottis swelled up and hinder swallowing pictures taken benadryl tylenol taken.",
"about 15 minutes after receiving the vaccine, the patient complained about her left arm hurting. she also complained of chest tightness and difficulty swallowing. patient also had vision changes. we gave the patient 1 tablet of benadryl 25 mg and called ems services. ems checked her out and we advised the patient to go to the er to be observed and given more benadryl.",
"death, extreme fatigue, dizziness,. could not lift my left arm for 72 hours" ,
"fever, chills, body aches, fatigue, shortness of breath, coughing, subsidied with painkillers" ,
"pins and needles in face started 12/29 er visit, physical exam. intermittent pins and needles continue" ,
"died", "death", "dead"
))
data %>%
mutate(DIED_EXTRA = str_detect(SYMPTOM, pattern = "died|death|dead"), .after = DIED) %>%
mutate(DIED = if_else(DIED == "Y", 1, 0)) %>%
mutate(DIED_EXTRA = DIED_EXTRA * 1) %>% #convert logical to numeric
mutate(DIED = if_else(DIED_EXTRA == 1, 1, DIED) )
#
# # A tibble: 8 x 3
# DIED DIED_EXTRA SYMPTOM
# <dbl> <dbl> <chr>
# 1 0 right side of epiglottis swelled up and hinder swallowing pictures taken benadryl tylenol taken.
# 0 0 about 15 minutes after receiving the vaccine, the patient complained about her left arm hurting. she also…
# 1 1 death, extreme fatigue, dizziness,. could not lift my left arm for 72 hours
# 1 1 fever, chills, body aches, fatigue, shortness of breath, coughing, subsidied with painkillers
# 0 0 pins and needles in face started 12/29 er visit, physical exam. intermittent pins and needles continue
# 1 1 died
# 1 1 death
# 1 1 dead