Sort a data.frame by a set of columns.

sortv(data, colnames, ..., na.last = TRUE, decreasing = FALSE,
  method = c("auto", "shell", "radix"))



data.frame to sort.


column names to sort on.


not used, force later arguments to bind by name.


(passed to order) for controlling the treatment of NAs. If TRUE, missing values in the data are put last; if FALSE, they are put first; if NA, they are removed.


(passed to order) logical. Should the sort order be increasing or decreasing? For the "radix" method, this can be a vector of length equal to the number of arguments in .... For the other methods, it must be length one.


(passed to order) the method to be used: partial matches are allowed. The default ("auto") implies "radix" for short numeric vectors, integer vectors, logical vectors and factors. Otherwise, it implies "shell". For details of methods "shell", "quick", and "radix", see the help for sort.


ordering permutation

See also


d <- data.frame(x = c(2, 2, 3, 3, 1, 1), y = 6:1) sortv(d, c("x", "y"))
#> x y #> 6 1 1 #> 5 1 2 #> 2 2 5 #> 1 2 6 #> 4 3 3 #> 3 3 4