I want to programmatically (loop or map) define the name of a variable, something like
for (i in 1:10) {
str_c("variable_", i) <- i
}
# or
map(1:10, ~{
str_c("variable_", .x) <- .x
}
)
so that, in this case, I end up with 10 vars in my environment, namely: variable_1, variable_2, ..., variable_10.
but I get the following error
" Error in str_c("variable_", i) <- 1 : target of assignment expands to non-language object "
Is there a way to achieve what I want to achieve?
Cheers