How to count observations per ID in R?
Using the data.table structure (see the wiki),

library(data.table)
D &lt;- data.table(x = c(1155, 1156, 1157, 1158),
                date = as.Date(c("2010-05-02", "2010-05-05", "2010-05-08", "2010-05-11")),
                y = c(2.7200, 2.6000, 2.6700, 3.5700),
                id = c(1, 3, 1, 2))
counts &lt;- D[, .(rowCount = .N), by = id]
counts


This will return

counts
##    id rowCount
## 1:  1        2
## 2:  3        1
## 3:  2        1