I am trying to create a dummy variable based on the string value of another variable the new dummy variable is including compound words. My question is how to get around this so it only includes the word in the quotes.
Syntax example "toke" = dataframe and "word" = a tokenized column of individual words when I run the syntax it correctly codes "product" as 1 in the new variable (toke2$product
) but it will also code productdesign as a 1. I want it to only code product as 1 and productdesign as 0.
tags <- c("product", "productdesign", "electronics")
line <- c("Bears", "Orcids", "Oranges")
toke = data.frame(toke, tags)
toke
toke2 <- toke%>% mutate(
product = ifelse(str_detect(word, "product"), "1", "0"))