user3056633 user3056633 - 24 days ago 22
R Question

How to merge three .RData files with same object name in R

I am a new user of R. I have three RData files with the same object name and I want to merge it so that I will have one .Rdata file with one object name.

Example:


  • file1.RData with object name A

  • file2.RData with object name A

  • file3.RData with object name A



and Result should be


  • file.RData = object A



I tried rbind and merge command, but nothing is working.

Answer

You will need to save them as new objects as you load each, then do your merging. For example, here, create a list to hold the objects. Then, as you load each, add that version to your list.

listForFiles <- list()

load("file1.RData")
listForFiles[[1]] <- A

load("file2.RData")
listForFiles[[2]] <- A

load("file3.RData")
listForFiles[[3]] <- A

Then, you can use listForFiles to do your merging. Since you don't say what kind of object these are, I can't suggest an approach.

Comments