I want to use a function to search for a word (or words) in a column and create a dummy variable that is 1 if a word is present and 0 if it is absent. The lines below yield no error message but also no result. What am I doing wrong? Adding !! and := does not seem to help. Thanks in advance.
library(tidyverse)
Sentences <- c("me love brown cookies", "I like blue and green", "c is for cookie", "I am fuzzy and blue")
df <- as.data.frame(Sentences)
# Define function
FindWordMakeDummy <- function(VarName, SearchWord) {
df <- df %>%
mutate(VarName = (as.integer(as.logical(str_detect(Sentences, SearchWord)))))
}
# Apply function
FindWordMakeDummy("Cookies", "cookie")
FindWordMakeDummy("Color", "green|blue|brown")