[英]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. 我有多个.RData文件,我需要将它们的一个对象保存为数据框。 For instance, I have 5 Rdata file in certain folder and I see it like this,
例如,我在某个文件夹中有5个Rdata文件,我看到了这样的内容,
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 每个RData都有带有名称的对象,例如
names(Results.alt_ID.RData)
And I need the object named table to be saved as a new seperate data frame for each Rdata 我需要将名为table的对象保存为每个Rdata的新单独数据帧
I need the object table saved as a dataframe from each of these .Rdata files. 我需要将每个.Rdata文件中的对象表另存为数据框。 Is there a way I could do it within a function?
有什么办法可以在函数中执行此操作吗?
My list of file names are pretty simple, "mt.Rdata" and "mt1.Rdata" 我的文件名列表非常简单,分别是“ mt.Rdata”和“ 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. 让我知道这是否是您想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.