DataCamp课程的官方速查表 原文链接:data-table-data-manipulation-r-tutorial
通用格式: DT[i, j, by],对于数据集DT,选取子集行i,通过by分组计算j
生成一个data.table对象,记为DT.
> library(data.table)
> set.seed(45L)
> DT <- data.table(V1=c(1L,2L),
+ V2=LETTERS[1:3],
+ V3=round(rnorm(4),4),
+ V4=1:12)
> DT
V1 V2 V3 V4
1: 1 A -1.1727 1
2: 2 B -0.3825 2
3: 1 C -1.0604 3
4: 2 A 0.6651 4
5: 1 B -1.1727 5
6: 2 C -0.3825 6
7: 1 A -1.0604 7
8: 2 B 0.6651 8
9: 1 C -1.1727 9
10: 2 A -0.3825 10
11: 1 B -1.0604 11
12: 2 C 0.6651 12