I'm trying to create a loop that goes from 1 to 14. Each integer in this loop would be added to the end of the name of a newly created dataframe. Then, it should search a column in an existing dataframe based on the concatenation of a number and text. I've been searching for hours but cannot find a solution.
What I mean is:
while (i <= 14) {
"newDF" + i <- oldDf %>%
filter(str_detect(ColumnName, "TEXT" + i)
}
The new dataframes should look like this:
newDF1,newDF2... newDF14
They should be created based on a concatenated string (text + i):
text1,text2..text14
My first challenge is to create a new dataframe based on the concatenation of text and i. I've tried using the str_c command and the str_glue command but get the following error message.
Error in str_c("newDF", i)) <- oldDF:
target of assignment expands to non-language object
Error in str_glue("newDF{i}") <- oldDF:
target of assignment expands to non-language object