I would like to check if at least one element of my data_frame_1 is in data_frame_2 and add it like a new column
my code:
library(data.table)
object_to_check <- data.table(c('aaax', 'bbbx', 'cccy', 'dddk', 'mmmt'))
colnames(object_to_check) <- 'x'
list_of_element <- data.table(c('ax', 'kh', 'dk'))
colnames(list_of_element) <- 'y'
Fun2 <- function(element_to_find, string_to_check) {
element_to_find <- '0'
if (element_to_find == '0') {
for (i in 1:length(list_of_element)) {
m <- lista[i]
element_to_find <- ifelse(grepl(m, string_to_check, ignore.case = T) == T,string_to_check,'')
}
}
}
object_to_check <- object_to_check[, check := Fun2(check, x)]
my code give me this error:
Warning message:
In `[.data.table`(object_to_check, , `:=`(check, Fun2(check, x))) :
Adding new column 'check' then assigning NULL (deleting it).
I'm stuck on this error and i can't find a solution on my problem. Can sameone help me?
Desired output:
x check
aaax ax
bbbx NA
cccx NA
dddk dk
mmmt NA
Thanks