Skip to Content
Data Analysis with R, Second Edition - Second Edition
book

Data Analysis with R, Second Edition - Second Edition

by Tony Fischetti
March 2018
Beginner to intermediate content levelBeginner to intermediate
570 pages
13h 42m
English
Packt Publishing
Content preview from Data Analysis with R, Second Edition - Second Edition

The i in DT [i, j, by]

In this subsection, we focus on the first third of  data.table square bracket syntax. Specifically, this is the third responsible for selecting and filtering rows: the WHERE clause, using SQL parlance.

Take the four simplest examples in the following code. These select (a) the first row, (b) the first, second, and third rows, (c) the first row (again), and second row, and (d) the last row. This is illustrated in the following code:

> tracks[1, ]> tracks[1:3, ]> tracks[c(1,1,2)]> tracks[.N, ]

There are two main things to note here. We can see the first by taking a closer look at the third statement. Note that, unlike the others, we don’t use a comma at the end. If this were a data.frame, the result would be a selection ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Exploratory Data Analysis with R

Hands-On Exploratory Data Analysis with R

Radhika Datar, Harish Garg
Bayesian Data Analysis, Third Edition, 3rd Edition

Bayesian Data Analysis, Third Edition, 3rd Edition

Andrew Gelman, John B. Carlin, Hal S. Stern, David B. Dunson, Aki Vehtari, Donald B. Rubin
R: Data Analysis and Visualization

R: Data Analysis and Visualization

Tony Fischetti, Brett Lantz, Jaynal Abedin, Hrishi V. Mittal, Bater Makhabel, Edina Berlinger, Ferenc Illés, Milán Badics, Ádám Banai, Gergely Daróczi, Barbara Dömötör, Gergely Gabler, Dániel Havran, Péter Juhász, István Margitai, Balázs Márkus, Péter Medvegyev, Julia Molnár, Balázs Árpád Szucs, Ágnes Tuza, Tamás Vadász, Kata Váradi, Ágnes Vidovics-Dancs

Publisher Resources

ISBN: 9781788393720Supplemental Content