Jonathan
Jonathan

Reputation: 641

How do I reassign a variable name in R?

I am loading from .rda files and the variable in the rda files are called "result"

I want to change the name of result after I load in a function call. I am unsure how to rename a variable in a function.

Say I want to change the name to

new_name_result <- result

I can do this explicitly, but I am loading from multiple .rda files and want to do something pro-grammatically.

paste0(new_name ,"_result") <- result

Something similar to this so the name can change with the name of the different .rda file.

Upvotes: 0

Views: 824

Answers (1)

cirofdo
cirofdo

Reputation: 1074

Simply like this:

assign(paste0("new_name", "_result"), result)

Upvotes: 2

Related Questions