R中data.frame和data.table之间的实际区别是什么 [英] What is the practical difference between data.frame and data.table in R

查看:25
本文介绍了R中data.frame和data.table之间的实际区别是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,在我的最后一个问题中,我展示了 data.framedata.table 之间的混淆.诚然,我没有意识到有区别.

Apparently in my last question I demonstrated confusion between data.frame and data.table. Admittedly, I didn't realize there was a distinction.

因此,我阅读了每种方法的帮助,但实际上,日常用语,有什么区别,有什么含义以及每种方法的用途将有助于指导我正确使用它们?

So I read the help for each but in practical, everyday terms, what is the difference, what are the implications and what are each used for that would help guide me to their appropriate usage?

推荐答案

虽然这是一个广泛的问题,但如果有人是 R 的新手,这可能会造成混淆,并且可能会失去区别.

While this is a broad question, if someone is new to R this can be confusing and the distinction can get lost.

所有 data.table 也是 data.frame.粗略地说,您可以将 data.tables 视为具有额外功能的 data.frames.

All data.tables are also data.frames. Loosely speaking, you can think of data.tables as data.frames with extra features.

data.frame 是基本 R 的一部分.

data.frame is part of base R.

data.table 是一个扩展data.frames 的包.它最显着的两个特性是速度和更简洁的语法.

data.table is a package that extends data.frames. Two of its most notable features are speed and cleaner syntax.

但是,这种语法糖与 data.frame 的标准 R 语法不同,而且未经训练的眼睛很难一目了然.因此,如果您阅读代码片段并且没有其他上下文表明您正在使用 data.tables 并尝试将代码应用于 data.frame 可能会失败或产生意外结果.(除了 library/require 调用之外,您正在使用 d.t 的一个明确的赠品是赋值运算符 := 的存在是 dt 独有的)

However, that syntax sugar is different from the standard R syntax for data.frame while being hard for the untrained eye to distinguish at a glance. Therefore, if you read a code snippet and there is no other context to indicate you are working with data.tables and try to apply the code to a data.frame it may fail or produce unexpected results. (a clear giveaway that you are working with d.t's, besides the library/require call is the presence of the assignment operator := which is unique to d.t)

话虽如此,我认为如果不体验data.frame的缺点,很难真正欣赏data.table的美感.(例如,请参阅@eddi 答案的前 3 个要点).换句话说,我非常建议先学习如何使用和操作data.frames,然后再学习data.tables.

With all that being said, I think it is hard to actually appreciate the beauty of data.table without experiencing the shortcomings of data.frame. (for example, see the first 3 bullet points of @eddi's answer). In other words, I would very much suggest learning how to work with and manipulate data.frames first then move on to data.tables.

这篇关于R中data.frame和data.table之间的实际区别是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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