I have a table with description of symptoms like below:
DT <- data.table(no = c(1, 2, 3),
symptom = c("headache and numbness", "tachycardia, sometimes headahce", "breath difficulty with limb numbness"))
the keywords I'm focusing on look like this
key.word <- list(
head = c("head", "headache"),
chest = c("breath", "tachycardia", "palpitaion")
I want to add two columns that describe whether the keyword is mentioned in the variable symptom, the desirable result looks like this
result <- data.table(no = c(1, 2, 3),
symptom = c("headache and numbness", "tachycardia, sometimes headahce", "breath difficulty with limb numbness"),
head = c(T, T, F),
chest = c(F, T, T))
I can do this job by
DT[symptom %like% paste0(head, collapse = "|"), head := T]
DT[symptom %like% paste0(chest, collapse = "|"), chest := T]
But I'm wondering if there is a way to do this with lapply and datatable? (which seemed to be more elegant). Thanks in advance!