Data Table

Facts about data.table.

  • Extends from data.frame and therefore should provide the same API.

  • Is written in C and is really fast.

  • Much faster at subsetting, grouping and updating.

Hello world

install.packages("data.table")
library(data.table)

years = c(2012, 2013)
average = c(250, 275)
table.values <- data.table(year = years, averageBeerConsumption = average)

See all data.table tables created in memory.

tables()

Subsetting rows.

Access row on specific index.

table.values[2]
table.values[c(1,2)]

Access rows that fulfil a condition.

Calculate values from columns

Return table of values for a column

Add new column

Multiple operations.

Plyr like operations

Grouping by

Count number of occurrences

Keys

Making table faster by setting the keys

Then we can join tables by keys.

Fast reading

First we create a file that we can use to test speed of reading.

Slow approach using read.table function.

Faster approach using fread function.

Last updated

Was this helpful?