special-symbols in package(data.table)
===================================================================================
The general form of data.table syntax is:
DT[ i, j, by ] # + extra arguments | | | | | -------> grouped by what? | -------> what to do? ---> on which rows?
===================================================================================
.SD , .SDcols , .N 等
.SD stands for something like "Subset of Data.table". There's no significance to the initial ".",
except that it makes it even more unlikely that there will be a clash with a user-defined column name.(注: .SD相当于对行操作,取数据集的子集)
.SDcols Specifies the columns of x
to be included in the special symbol, subset of columns . (注: .SD相当于对列操作,取符合条件的列)
.N可以用来表示行的数量或者最后一行
===================================================================================
.SD
, .BY
, .N
, .I
and .GRP
are read only symbols for use in j
。 .N
can be used in i
as well. See the vignettes and examples here and in data.table
.
DT[.N] # last row, only special symbol allowed in 'i' DT[, .N] # total number of rows in DT DT[, .SD, .SDcols=x:y] # select columns 'x' and 'y'
===================================================================================