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

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

问题描述

我根据一组推特制作了一个数据框,格式如下:

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")

我应用 dim(df2) 它应该返回数据框拥有的推文数量,但它只显示 1.

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

推荐答案

正如@mrdwab 指出的那样,save 保存名称以及数据/结构(实际上可以保存许多单个文件中的不同 R 对象).还有另一对存储函数的行为更符合您的预期.试试这个:

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天全站免登陆