O'Reilly logo

Data Analysis with R - Second Edition by Tony Fischetti

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The j in DT[i, j, by]

In this subsection, we focus on the second third of data.table’s square bracket syntax; this is the third responsible for selecting and filtering columns like the SELECT clause in SQL.

Much like we didn’t have to use the name of the data table and the $ operator when selecting and filtering rows, we can just use the bare names of columns in the j section.

Check out the following four lines of code:

> tracks[, trackname][1] "A Perfect Match" "Mamma Mia"       "Upside Down"     "Upside Down"     "Mamma Mia"> tracks[, .(trackname)]                                      trackname     1:                         A Perfect Match     2:                               Mamma Mia     3:                             Upside Down# ....> tracks[, .(trackname, artist)]                                      trackname          artist     1:                         A Perfect Match         A*Teens     2:                               Mamma Mia         A*Teens     3:                             Upside Down         A*Teens> # semantically equivalent ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required