[英]How to convert .Rdata format into text file format
I am a novice in R and I am trying to convert .Rdata format file into comma delimited text file format.我是 R 的新手,我正在尝试将 .Rdata 格式文件转换为逗号分隔的文本文件格式。 Can someone help me out regarding this?
有人可以帮我解决这个问题吗?
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.一个
.RData
文件可以包含任何类的 1 个以上的对象。
If your file contains more than 1 object of data.frame
-like class, then the following should work如果您的文件包含超过 1 个
data.frame
类的对象,则以下内容应该有效
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.您可以更改对
write.csv
的调用以执行您想要的操作。 If your objects won't behave nicely with write.csv
, then you shouldn't be trying this.如果您的对象在
write.csv
表现write.csv
,那么您不应该尝试这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.