How to open multiple .RDATA and save one of there names as data.frame

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?


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.

链接地址: http://www.djcxy.com/p/38376.html

上一篇: 自动将功能输出(列表)分解为组件数据帧

下一篇: 如何打开多个.RDATA并将其中一个名称保存为data.frame