Converting Rdata files to CSV - Error in data.frame arguments imply differing number of rows

谁都会走 提交于 2019-12-01 12:13:19
42-

That answer was designed to handle object of class-'data.frame'. You only have an object of class-'list' which happens to have items that are dataframes. So there isn't an object with the name "2" in you workspace but there is an element in the 'dataa'-list that is named "2" and all of the other elements appear to also be dataframes, so why not use:

lapply( names(dataa), function(nam) write.csv( data[[nam]], file=paste0(nam, ".Rdata") ) )

I'll vote for the other answer, but here's some almost working code:

resave <- function(file){
  e <- new.env(parent = emptyenv())
  load(file, envir = e)
  obj <- get('dataa', envir =e)
  lapply( names(obj), function(nam) {
    write.csv( obj[[nam]], file=paste(nam, ".csv", sep="") )
    cat(sprintf('%s.csv
', nam) )
    }
   )
}
resave("indiv8-hmmprob.RData")

Here's the output. which works but it's throwing in some wierd printed stuff at the end, the [[1]] NULL, etc.

2.csv
3.csv
4.csv
X.csv
[[1]]
NULL

[[2]]
NULL

[[3]]
NULL

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