在提要中,类“ tbl”的对象与对象之间的区别是什么?和“ tbl_df”? [英] In the tidyverse, what is the difference between an object of class "tbl" and "tbl_df"?

查看:313
本文介绍了在提要中,类“ tbl”的对象与对象之间的区别是什么?和“ tbl_df”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建小标题时,

tbl <- tibble(A=1:5, B=6:10)

class(tbl)

[1] "tbl_df"     "tbl"        "data.frame"

我经常使用dplyr来看到它。但是什么时候对象只是一个 tbl(而不是 tbl_df),反之亦然?我想进一步了解两者之间的区别(如果有)。

I'm used to seeing this as I use dplyr quite a bit. But when is an object just a "tbl" (and not a "tbl_df") or vice versa? I'd just like to know a bit more about the difference, if any.

任何文档将不胜感激!

推荐答案

您可以认为小工具作为界面。如果对象可以响应所有微动动作,则可以将其视为微动。 R没有强力打字。

You can think of a "tibble" as an interface. If an object can respond to all the tibble actions, then you can think of it as a tibble. R doesn't have strong typing.

所以 tbl 是通用小标题,而 tbl_df

So tbl is the generic tibble, and tbl_df is a specific type of tibble that basically stores it's data in a data.frame.

还有其他软件包,例如 dtplyr 允许您像小标题一样将数据存储在 data.table 中。例如

There are other packages like dtplyr that allow you to act like a tibble but store your data in a data.table. For example

library(dtplyr)
ds <- tbl_dt(mtcars)
class(ds)
# [1] "tbl_dt"     "tbl"        "data.table" "data.frame"

还有 dbplyr 软件包,它允许您使用SQL数据库后端。例如,

There's also the dbplyr package which allows you to use a SQL database back end. For example

library(dplyr)
con <- DBI::dbConnect(RSQLite::SQLite(), path = ":memory:")
copy_to(con, mtcars, "mtcars",temporary = FALSE)
cars_db <- tbl(con, "mtcars")
class(cars_db)
# [1] "tbl_dbi"  "tbl_sql"  "tbl_lazy" "tbl"  

再次,我们看到这东西通常可以充当小工具,但是它还有其他类,因此它可以尝试完成数据库引擎中的所有工作,而不是操纵R本身中的数据。

So again we see that this thing generally can act as a tibble, but it has other classes that are there so that it can try to do all it's work in the database engine, rather than manipulating the data in R itself.

因此 tbl tbl_df 之间并没有真正的区别。后者只是说明小标题的实际实现方式,因此行为可以有所不同(可以更优化)。

So there's not really a "difference" between tbl and tbl_df. The latter just says how the tibble is actually being implemented so the behavior can differ (be more optimized).

有关更多信息,您可以查看小插图扩展小装饰图案

For more information, you can check out the tibble vignette or the extending tibble vignette

这篇关于在提要中,类“ tbl”的对象与对象之间的区别是什么?和“ tbl_df”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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