I made a data.frame in R that is not very big, but it takes quite some time to build. I would to save it as a file, which I can than again open in R?
我做了一个数据,用R表示的框架不是很大,但它需要花费很多时间。我会把它保存为一个文件,这样我就可以在R中打开它了?
2 个解决方案
#1
140
There are several ways. One way is to use save()
to save the exact object. e.g. for data frame foo
:
有几种方法。一种方法是使用save()保存确切的对象。例如,数据帧foo:
save(foo,file="data.Rda")
Then load it with:
然后加载:
load("data.Rda")
You could also use write.table()
or something like that to save the table in plain text, or dput()
to obtain R code to reproduce the table.
还可以使用write.table()或类似的方法将表保存为纯文本,或者使用dput()获取R代码以复制表。
#2
67
If you are only saving a single object (your data frame), you could also use saveRDS
.
To save:
如果只保存一个对象(数据帧),也可以使用saveRDS。保存:
saveRDS(foo, file="data.Rda")
Then read it with:
然后读:
bar <- readRDS(file="data.Rda")
The difference between saveRDS
and save
is that in the former only one object can be saved and the name of the object is not forced to be the same after you load it.
saveRDS和save之间的不同之处在于,在前者中只能保存一个对象,并且在加载后不会强制要求对象的名称保持相同。
#1
140
There are several ways. One way is to use save()
to save the exact object. e.g. for data frame foo
:
有几种方法。一种方法是使用save()保存确切的对象。例如,数据帧foo:
save(foo,file="data.Rda")
Then load it with:
然后加载:
load("data.Rda")
You could also use write.table()
or something like that to save the table in plain text, or dput()
to obtain R code to reproduce the table.
还可以使用write.table()或类似的方法将表保存为纯文本,或者使用dput()获取R代码以复制表。
#2
67
If you are only saving a single object (your data frame), you could also use saveRDS
.
To save:
如果只保存一个对象(数据帧),也可以使用saveRDS。保存:
saveRDS(foo, file="data.Rda")
Then read it with:
然后读:
bar <- readRDS(file="data.Rda")
The difference between saveRDS
and save
is that in the former only one object can be saved and the name of the object is not forced to be the same after you load it.
saveRDS和save之间的不同之处在于,在前者中只能保存一个对象,并且在加载后不会强制要求对象的名称保持相同。