简体   繁体   中英

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

I am a completely a beginner in r language. I need to read a .rdata file that contains a list of several matrices. The length of the list is 551 and the matrices it contains have the same dimensions of 462 x 961.

I want to write each of these matrices in a separate .csv file hence I will finally have 551 .csv files.
I am not able to do that. Somehow, I was able to read the .rdata file by using the following code.

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)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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