Skip to content

Commit 658c529

Browse files
authored
Merge pull request #6155 from Rdatatable/Document_NATURAL
Documentation for .NATURAL
2 parents 8ccadc6 + 59b3704 commit 658c529

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

man/special-symbols.Rd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
\alias{.N}
99
\alias{.EACHI}
1010
\alias{.NGRP}
11+
\alias{.NATURAL}
1112
\title{ Special symbols }
1213
\description{
1314
\code{.SD}, \code{.BY}, \code{.N}, \code{.I}, \code{.GRP}, and \code{.NGRP} are \emph{read-only} symbols for use in \code{j}. \code{.N} can be used in \code{i} as well. \code{.I} can be used in \code{by} as well. See the vignettes, Details and Examples here and in \code{\link{data.table}}.
14-
\code{.EACHI} is a symbol passed to \code{by}; i.e. \code{by=.EACHI}.
15+
\code{.EACHI} is a symbol passed to \code{by}; i.e. \code{by=.EACHI}, \code{.NATURAL} is a symbol passed to \code{on}; i.e. \code{on=.NATURAL}
1516
}
1617
\details{
1718
The bindings of these variables are locked and attempting to assign to them will generate an error. If you wish to manipulate \code{.SD} before returning it, take a \code{copy(.SD)} first (see FAQ 4.5). Using \code{:=} in the \code{j} of \code{.SD} is reserved for future use as a (tortuously) flexible way to update \code{DT} by reference by group (even when groups are not contiguous in an ad hoc by).
@@ -29,6 +30,8 @@
2930
3031
\code{.EACHI} is defined as \code{NULL} but its value is not used. Its usage is \code{by=.EACHI} (or \code{keyby=.EACHI}) which invokes grouping-by-each-row-of-i; see \code{\link{data.table}}'s \code{by} argument for more details.
3132

33+
\code{.NATURAL} is defined as \code{NULL} but its value is not used. Its usage is \code{on=.NATURAL} (alternative of \code{X[on=Y]}) which joins two tables on their common column names, performing a natural join; see \code{\link{data.table}}'s \code{on} argument for more details.
34+
3235
Note that \code{.N} in \code{i} is computed up-front, while that in \code{j} applies \emph{after filtering in \code{i}}. That means that even absent grouping, \code{.N} in \code{i} can be different from \code{.N} in \code{j}. See Examples.
3336
}
3437
\seealso{
@@ -54,6 +57,7 @@ DT[, c(.(y=max(y)), lapply(.SD, min)),
5457
DT[, grp := .GRP, by=x] # add a group counter
5558
DT[, grp_pct := .GRP/.NGRP, by=x] # add a group "progress" counter
5659
X[, DT[.BY, y, on="x"], by=x] # join within each group
60+
DT[X, on=.NATURAL] # join X and DT on common column similar to X[on=Y]
5761
5862
# .N can be different in i and j
5963
DT[{cat(sprintf('in i, .N is \%d\n', .N)); a < .N/2},

0 commit comments

Comments
 (0)