Counting in R data.table
- by Simon Z.
I have the following data.table
set.seed(1)
DT <- data.table(VAL = sample(c(1, 2, 3), 10, replace = TRUE))
VAL
1: 1
2: 2
3: 2
4: 3
5: 1
6: 3
7: 3
8: 2
9: 2
10: 1
Now I want to to perform two tasks:
Count the occurrences of numbers in VAL.
Count within all rows with the same value VAL (first, second, third…