One of the biggest benefits of using data.table
is that you can set a key for your data.
Using the key
and then .I
(a built in vairable. see ?data.table
for more info) you can use:
setkey(DT, site)
DT[DT["a", sample(.I, 100)]]
As for your second question "how can I access a row number in data.table's i argument"
# Just use the number directly:
DT[17]