Analogous function for arrange in dplyr.

arrange(.data, ..., cols = NULL, order = 1L)

Arguments

.data

data.frame

...

Arrange by what group? Minus symbol means arrange by descending order.

cols

For set_arrange only. A character vector of column names of .data by which to order. If present, override .... Defaults to NULL.

order

For set_arrange only. An integer vector with only possible values of 1 and -1, corresponding to ascending and descending order. Defaults to 1.

Value

A data.table

Details

Once arranged, the order of entries would be changed forever.

See also

Examples


a = as.data.table(iris)
a %>% arrange(Sepal.Length)
#>      Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
#>             <num>       <num>        <num>       <num>    <fctr>
#>   1:          4.3         3.0          1.1         0.1    setosa
#>   2:          4.4         2.9          1.4         0.2    setosa
#>   3:          4.4         3.0          1.3         0.2    setosa
#>   4:          4.4         3.2          1.3         0.2    setosa
#>   5:          4.5         2.3          1.3         0.3    setosa
#>  ---                                                            
#> 146:          7.7         3.8          6.7         2.2 virginica
#> 147:          7.7         2.6          6.9         2.3 virginica
#> 148:          7.7         2.8          6.7         2.0 virginica
#> 149:          7.7         3.0          6.1         2.3 virginica
#> 150:          7.9         3.8          6.4         2.0 virginica
a
#>      Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
#>             <num>       <num>        <num>       <num>    <fctr>
#>   1:          4.3         3.0          1.1         0.1    setosa
#>   2:          4.4         2.9          1.4         0.2    setosa
#>   3:          4.4         3.0          1.3         0.2    setosa
#>   4:          4.4         3.2          1.3         0.2    setosa
#>   5:          4.5         2.3          1.3         0.3    setosa
#>  ---                                                            
#> 146:          7.7         3.8          6.7         2.2 virginica
#> 147:          7.7         2.6          6.9         2.3 virginica
#> 148:          7.7         2.8          6.7         2.0 virginica
#> 149:          7.7         3.0          6.1         2.3 virginica
#> 150:          7.9         3.8          6.4         2.0 virginica
a %>% arrange(cols = c("Sepal.Width","Petal.Length"))
#>      Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
#>             <num>       <num>        <num>       <num>     <fctr>
#>   1:          5.0         2.0          3.5         1.0 versicolor
#>   2:          6.0         2.2          4.0         1.0 versicolor
#>   3:          6.2         2.2          4.5         1.5 versicolor
#>   4:          6.0         2.2          5.0         1.5  virginica
#>   5:          4.5         2.3          1.3         0.3     setosa
#>  ---                                                             
#> 146:          5.4         3.9          1.7         0.4     setosa
#> 147:          5.8         4.0          1.2         0.2     setosa
#> 148:          5.2         4.1          1.5         0.1     setosa
#> 149:          5.5         4.2          1.4         0.2     setosa
#> 150:          5.7         4.4          1.5         0.4     setosa
a
#>      Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
#>             <num>       <num>        <num>       <num>     <fctr>
#>   1:          5.0         2.0          3.5         1.0 versicolor
#>   2:          6.0         2.2          4.0         1.0 versicolor
#>   3:          6.2         2.2          4.5         1.5 versicolor
#>   4:          6.0         2.2          5.0         1.5  virginica
#>   5:          4.5         2.3          1.3         0.3     setosa
#>  ---                                                             
#> 146:          5.4         3.9          1.7         0.4     setosa
#> 147:          5.8         4.0          1.2         0.2     setosa
#> 148:          5.2         4.1          1.5         0.1     setosa
#> 149:          5.5         4.2          1.4         0.2     setosa
#> 150:          5.7         4.4          1.5         0.4     setosa