Suppose I have an .rda
file created using save()
. Example:
save(mydata1, file = "anrdatafile.rda")
where, mydata1
is a data frame.
I want to write code in R
which: (1) loads the 'anrdatafile.rda' file; (2) finds the name of the data frame in that file (3) combines the found data frame with another data frame say mydata2
.
How do I achieve step 2? Once I have the name of the data frame in step 2, I can do
combineddata = rbind(mydata1, mydata2)
But I don't know how to get that the name of the dataframe in the .rda file is mydata1
as a part of a code.
I tried
nameofthedataframe = load('anrdatafile.rda')
This assigns the string "mydata1" to the variable "nameofthedataframe", but then how do I get the data in the data frame mydata1
?
To clarify, I know I can use the same data frame name that was to used to save the data. However, suppose I forget what the variable was. Or, more importantly, I would have to hard code the variable name in my code. I was wondering whether the program could figure out the name of the data frame during the run time once I gave it the file name.
Thanks. If it is not clear, please let me know. I will try to clarify.