How to convert .Rdata format into text file format

谁都会走 提交于 2019-11-30 17:39:58
load("yourData.RData")
ls() #returns a list of all the objects you just loaded (and anything else in your environment)
write.csv(theItemOfInterestFromYourDRadataFileAsThereMayBeMoreThanOneThingInthere,
  file="yourCSV.csv")

An .RData file can contain more than 1 object of any class.

If your file contains more than 1 object of data.frame-like class, then the following should work

resave <- function(file){
  e <- new.env(parent = emptyenv())
  load(file, envir = e)
  objs <- ls(envir = e, all.names = TRUE)
  for(obj in objs) {
    .x <- get(obj, envir =e)
    message(sprintf('Saving %s as %s.csv', obj,obj) )
    write.csv(.x, file = paste0(obj, '.csv'))
  }
}

  resave('yourData.RData')

You can change the call to write.csv to do what you want. If your objects won't behave nicely with write.csv, then you shouldn't be trying this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!