1
votes

I have a multiple .RData files and I need to save one of their objects as a data frame. For instance, I have 5 Rdata file in certain folder and I see it like this,

files <- list.files(path="/home/user/data/bumphunter", pattern="*.RData", full.names=TRUE, recursive=FALSE)

which shows me,

files
[1] "/home/R1/Results.alt_ID.RData" 
[2] "/home/R1/Results.alt.RData"    
[3] "/home/R1/Results.alt_REL.RData"
[4] /home/R1/Results.DU_ID.RData"   
[5] "/home/R1/Results.DU.RData"      
[6] "/home/R1/Results.DU_REL.RData"  
[7] "/home/R1/Results.P_ID.RData"   
[8] "/home/R1/Results.P.RData"      
[9] "/home/R1/Results.P_REL.RData" 

And each RData has objects with names for example

names(Results.alt_ID.RData)

And I need the object named table to be saved as a new seperate data frame for each Rdata

I need the object table saved as a dataframe from each of these .Rdata files. Is there a way I could do it within a function?

1

1 Answers

2
votes

My list of file names are pretty simple, "mt.Rdata" and "mt1.Rdata"

The code I have for having dataframes for every file is

files <- list.files(getwd())


for(i in files){
    print(i)
    df <- load(i)
    assign(gsub("\\..*","", i), df ) #extracts the string before period
    rm(df)
    }

Let me know if this is what your are looking for.