Order the rows of a data frame rows by the values of selected columns.

arrange_dt(.data, ...)

Arguments

.data

data.frame

...

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

Value

data.table

See also

Examples


iris %>% arrange_dt(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

# minus for decreasing order
iris %>% arrange_dt(-Sepal.Length)
#>      Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
#>             <num>       <num>        <num>       <num>    <fctr>
#>   1:          7.9         3.8          6.4         2.0 virginica
#>   2:          7.7         3.8          6.7         2.2 virginica
#>   3:          7.7         2.6          6.9         2.3 virginica
#>   4:          7.7         2.8          6.7         2.0 virginica
#>   5:          7.7         3.0          6.1         2.3 virginica
#>  ---                                                            
#> 146:          4.5         2.3          1.3         0.3    setosa
#> 147:          4.4         2.9          1.4         0.2    setosa
#> 148:          4.4         3.0          1.3         0.2    setosa
#> 149:          4.4         3.2          1.3         0.2    setosa
#> 150:          4.3         3.0          1.1         0.1    setosa

# arrange by multiple variables
iris %>% arrange_dt(Sepal.Length,Petal.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         3.0          1.3         0.2    setosa
#>   3:          4.4         3.2          1.3         0.2    setosa
#>   4:          4.4         2.9          1.4         0.2    setosa
#>   5:          4.5         2.3          1.3         0.3    setosa
#>  ---                                                            
#> 146:          7.7         3.0          6.1         2.3 virginica
#> 147:          7.7         3.8          6.7         2.2 virginica
#> 148:          7.7         2.8          6.7         2.0 virginica
#> 149:          7.7         2.6          6.9         2.3 virginica
#> 150:          7.9         3.8          6.4         2.0 virginica