I'm trying to create a global variable by means of a function in R:
f <- function(name, value) {
name <<- value
}
if I type the command
f(x,3)
I get a global variable called 'name' with the value 3. However, I want the variable's name to be 'x' instead of 'name'
Does anyone know, how to solve this problem? :)
Edit: This is a stripped down and extremely simplified version of my problem. I know, there is the assign() command or also the '<-'-operator, both doing the same.
assign, where you provide the variable name as a character. No need to write your own function. Also, pay very careful attention to where the assignment takes place via theposorenvirarguments.assign. You can useassigninside a function or outside a function. If you've tried to use assign and found that it's not working. And you've paid attention to joran's whole comment and are being careful about where the assignment takes place, then post your code and we'll help you. Though most everyone on here will try to talk you out of it as it's almost always a Very Bad Idea.assignis that you don't want to pass the name as a character string, then you should look up introductory material on Non-Standard Evaluation. Therlangpackage is the new popular way to do that.