Skip to content

Commit bc36091

Browse files
committed
added example of sort_by
1 parent 81646e7 commit bc36091

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

NEWS.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@
1010

1111
### NEW FEATURES
1212

13-
1. New `sort_by()` method for data.tables, [#6662](https://github.com/Rdatatable/data.table/issues/6662). It uses `forder()` to improve upon the data.frame method and also match `DT[order(...)]` behavior with respect to locale. Thanks @rikivillalba for the suggestion and PR.
13+
1. New `sort_by()` method for data.tables, [#6662](https://github.com/Rdatatable/data.table/issues/6662). It uses `forder()` to improve upon the data.frame method and also match `DT[order(...)]` behavior with respect to locale, and allows sorting by expressions or functions. Thanks @rikivillalba for the suggestion and PR.
14+
15+
```r
16+
DT = data.table(a = c(1, 2, 1), b = c(3, 1, 2))
17+
# sort by column 'b'
18+
sort_by(DT, ~b)
19+
# a b
20+
# 1: 2 1
21+
# 2: 1 2
22+
# 3: 1 3
23+
```
1424

1525
2. `melt()` now supports using `patterns()` with `id.vars`, [#6867](https://github.com/Rdatatable/data.table/issues/6867). Thanks to Toby Dylan Hocking for the suggestion and PR.
1626

0 commit comments

Comments
 (0)