I am trying to create a variable inside a function in R, but the name of this variable depends on the parameter of the function, so I want to name it with paste.
I will show what I mean with an example:
variable <- function(name){
assign(paste0("variable_",name),1)
}
variable("one")
variable_one
How should I use the assign
command so I can access the variable outside the function? What I mean is that when I use variable_one
I get 1
(I know using <<-
, but not with assign
).
Any help will be appreciated.