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?
They are similar. Data frames are lists of vectors of equal length while data tables ( data. table ) is an inheritance of data frames. Therefore data tables are data frames but data frames are not necessarily data tables.
For the size of DF data. table is slower, for the size of DF2 it is faster.
table is the primary reason I prefer working in R rather than Python. Although R is notorious for being a slow language, data. table generally runs faster than Python's pandas (benchmark) and even gives Spark a run for its money as long as R can process the data of that size.
While this is a broad question, if someone is new to R
this can be confusing and the distinction can get lost.
All data.table
s are also data.frame
s. Loosely speaking, you can think of data.tables as data.frames with extra features.
data.frame
is part of base R
.
data.table
is a package that extends data.frames
. Two of its most notable features are speed and cleaner syntax.
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)
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.table
s.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With