简体   繁体   English

如何读取 .rdata 文件并从中写入 .csv 文件

[英]How can I read .rdata file and write .csv files from it

I am a completely a beginner in r language.我完全是 r 语言的初学者。 I need to read a .rdata file that contains a list of several matrices.我需要读取一个包含多个矩阵列表的 .rdata 文件。 The length of the list is 551 and the matrices it contains have the same dimensions of 462 x 961.列表的长度为 551,其中包含的矩阵具有相同的 462 x 961 维度。

I want to write each of these matrices in a separate .csv file hence I will finally have 551 .csv files.我想将这些矩阵中的每一个写入单独的 .csv 文件,因此我最终将拥有 551 个 .csv 文件。
I am not able to do that.我不能那样做。 Somehow, I was able to read the .rdata file by using the following code.不知何故,我能够使用以下代码读取 .rdata 文件。

load("/home/mondal/Documents/Dataset/seismic/seismic.RData", ex <- new.env())
ls.str(ex) 
print(length(ex[1].inline))

But then I don't know how to proceed.但后来我不知道如何继续。 It will be very helpful if someone can give me some working code to do that.如果有人可以给我一些工作代码来做到这一点,那将非常有帮助。 You can visualize my data structure from the image.您可以从图像中可视化我的数据结构。

在此处输入图片说明

You can do a loop where you set the path for where you want the data to be stored + the file name:您可以执行一个循环,在其中设置要存储数据的路径 + 文件名:

for(i in 1:551){
  path = paste("/home/mondal/RestOfThePath/FileNumber",i,".txt",sep="")
  write(inline[[i]], file=path)}

Finally, I solve the problem like this:最后,我解决了这样的问题:

load("/home/mondal/Documents/Dataset/seismic/seismic.RData", ex <- new.env())
ls.str(ex) 
print(length(ex))


for(i in 1:length(inline)){
    path = paste("/home/mondal/Documents/Dataset/seismic/Netherland_Data_CSV/FileNumber_",i,".csv",sep=",")
    df <- data.frame(inline[[i]])
    write.csv(df, file=path, row.names = FALSE)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM