I am not able to get the x variables in the mutate function in R below to become floating variables. Can someone please help me trouble shoot this code.
library(dplyr)
List<-c("Go","Rust")
env <- environment()
for (i in c(1:length(List))) {
x=List[i]
"x" %>% assign(List[i], envir = env)
print(x)
subData<-subData %>%
mutate(x = case_when( str_detect(ColumnName, "x") ~ 1, TRUE ~ 0))
}
Rust and Go are words that are being found in a column of strings and then a new column name is being created with that word. That is what the mutate function is doing.
These two lines of code work when I run them, but when I try and loop through the list they don't work.
subData <- subData %>%
mutate(Rust = case_when(str_detect(LanguageWantToWorkWith, "Rust") ~ 1,
TRUE ~ 0))
subData <- subData %>%
mutate(Go = case_when(str_detect(LanguageWantToWorkWith, "Go") ~ 1, TRUE
~ 0))
Thank you, Kelly Fitzpatrick
I can't get the x variable in the mutate function to loop through the list of words.

It seems to me that you just want to one-hot-encode a variable from a string of variables. Here is what I would do: