I have a dataset with a column Disease
that contains string values. I also have a list of names with rare diseases rare_disease
.
I want to check, for each cell of the column Disease
, whether it contains an element from the list rare_disease
and if so, to create a new column in my dataframe and give the value 1 to that entry.
I tried using the ifelse
function, like so:
FinalData$RareDisease <- ifelse(rare_disease %in% FinalData$Disease,1,0)
But I guess that checks whether the the corresponding rows in both variables are the same, so it throws an error. Instead, I want every cell of Disease
to be checked against every single element of rare_disease
, if that makes sense.
I have also tried match
and is.element()
as suggested here Test if a vector contains a given element but they don't work either.