保存并加载data.frames [英] Saving and loading data.frames

查看:107
本文介绍了保存并加载data.frames的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用以下形式的一组twitters数据框:

  rdmTweets<  -  userTimeline( rdatamining,n = 200)
df< - do.call(rbind,lapply(rdmTweets,as.data.frame))

现在我以这种方式保存数据框:

 保存(df,file =data)

如何加载保存的数据框以备将来使用?当我使用:

  df2<  -  load(data)
/ pre>

,我应用 dim(df2)它应该返回数据帧具有的tweets数量,但它只显示1。

解决方案

正如@mrdwab指出的, save 保存名称以及数据/结构(实际上可以在单个文件中保存多个不同的R对象)。还有另一对存储功能的行为更多,如您所料。尝试这样:

  saveRDS(df,file =mytweets.rds)
df2< - readRDS( mytweets.rds)

这些函数一次只能处理单个对象。


I have made a dataframe based on a set of twitters in the following form:

 rdmTweets <- userTimeline("rdatamining", n=200)
 df <- do.call("rbind", lapply(rdmTweets, as.data.frame))

Now I am saving the data frame with save in this way:

 save(df, file="data")

How I can load that saved data frame for future use? When I use:

  df2 <- load("data")

and I apply dim(df2) it should return the quantity of tweets that data frame has, but it only shows 1.

解决方案

As @mrdwab points out, save saves the names as well as the data/structure (and in fact can save a number of different R objects in a single file). There is another pair of storage functions that behave more as you expect. Try this:

saveRDS(df, file="mytweets.rds")
df2 <- readRDS("mytweets.rds")

These functions can only handle a single object at a time.

这篇关于保存并加载data.frames的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆