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 ...