55\alias {fastorder }
66\alias {forder }
77\alias {forderv }
8+ \alias {sort_by }
89
910\title {Fast row reordering of a data.table by reference }
1011\description {
@@ -32,6 +33,7 @@ setorderv(x, cols = colnames(x), order=1L, na.last=FALSE)
3233# optimised to use data.table' s internal fast order
3334# x[order(., na.last=TRUE)]
3435# x[order(., decreasing=TRUE)]
36+ # sort_by(x, ., na.last=TRUE, decreasing=FALSE)
3537}
3638\arguments {
3739\item {x }{ A \code {data.table }. }
@@ -46,7 +48,7 @@ when \code{b} is of type \code{character} as well. }
4648\code {order } must be either \code {1 } or equal to that of \code {cols }. If
4749\code {length(order ) == 1 }, it is recycled to \code {length(cols )}. }
4850\item {na.last }{ \code {logical }. If \code {TRUE }, missing values in the data are placed last ; if \code {FALSE }, they are placed first ; if \code {NA } they are removed.
49- \code {na.last = NA } is valid only for \code {x [order(. , na.last )]} and its
51+ \code {na.last = NA } is valid only for \code {x [order(. , na.last )]} and related \ code {sort_by( x , . )} and its
5052default is \code {TRUE }. \code {setorder } and \code {setorderv } only accept
5153\code {TRUE }/ \code {FALSE } with default \code {FALSE }. }
5254}
@@ -71,8 +73,8 @@ sets the \code{sorted} attribute.
7173
7274\code {na.last } argument , by default , is \code {FALSE } for \code {setorder } and
7375\code {setorderv } to be consistent with \code {data.table }' s \c ode{setkey} and
74- is \c ode{TRUE} for \c ode{x[order(.)]} to be consistent with \c ode{base::order}.
75- Only \c ode{x[order(.)]} can have \c ode{na.last = NA} as it is a subset operation
76+ is \c ode{TRUE} for \c ode{x[order(.)]} and \c ode{sort_by(x, .)} to be consistent with \c ode{base::order}.
77+ Only \c ode{x[order(.)]} (and related \c ode{sort_by(x, .)}) can have \c ode{na.last = NA} as it is a subset operation
7678as opposed to \c ode{setorder} or \c ode{setorderv} which reorders the data.table
7779by reference.
7880
@@ -96,6 +98,11 @@ was started in. By contrast, \code{"america" < "BRAZIL"} is always \code{FALSE}
9698
9799If \c ode{setorder} results in reordering of the rows of a keyed \c ode{data.table},
98100then its key will be set to \c ode{NULL}.
101+
102+ \c ode{sort_by(x, y, \d ots)} is the S3 method for the generic \c ode{sort_by} for \c ode{data.table}' s.
103+ It uses the same formula or list interfaces as data.frame ' s \c ode{sort_by} but internally uses \c ode{data.table}' s fast ordering ,
104+ hence it behaves the same as \code {x [order(. )]} and takes the same optional named arguments and their defaults.
105+
99106}
100107\value {
101108The input is modified by reference , and returned (invisibly ) so it can be used
0 commit comments