You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
new helper function fctr to retain order of input in levels, closes #… (#4843)
* new helper function fctr to retain order of input in levels, closes#4837
* wording
* fctr gets option to reverse order of levels
* add sort argument to fctr()
* augment NEWS
* more polish
* indent code block
* stop->stopf
* emphasize sort happens first
* polish Rd grammar
* test #ing
---------
Co-authored-by: Michael Chirico <[email protected]>
Copy file name to clipboardExpand all lines: NEWS.md
+22Lines changed: 22 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,28 @@
18
18
19
19
6.`between()` gains the argument `ignore_tzone=FALSE`. Normally, a difference in time zone between `lower` and `upper` will produce an error, and a difference in time zone between `x` and either of the others will produce a message. Setting `ignore_tzone=TRUE` bypasses the checks, allowing both comparisons to proceed without error or message about time zones.
20
20
21
+
7. New helper function `fctr` as an extended version of `factor()`, [#4837](https://github.com/Rdatatable/data.table/issues/4837). Most notably, it supports (1) retaining input level ordering by default, i.e. `levels=unique(x)` as opposed to `levels = sort(unique(x))`; (2) `rev=` to reverse the levels; and (3) `sort=` to allow more feature parity with `factor()`. The choice of default is motivated by convenience in the common case when order of elements needs be preserved, for example when using `dcast` or adding a legend to a plot. This also matches the default sort ordering of groups in `by=`.
dcast(d, id1~ fctr(id2, sort=TRUE)) # same as factor()
34
+
# id1 c d e
35
+
# 1: 1 2 1 3
36
+
# 2: 2 4 5 6
37
+
dcast(d, id1~ fctr(id2, rev=TRUE))
38
+
# id1 e c d
39
+
# 1: 1 3 2 1
40
+
# 2: 2 6 4 5
41
+
```
42
+
21
43
### BUG FIXES
22
44
23
45
1.Custombinaryoperatorsfromthe`lubridate`packagenowworkwithobjectsofclass`IDate`aswitha`Date`subclass, [#6839](https://github.com/Rdatatable/data.table/issues/6839). Thanks @emallickhossain for the report and @aitap for the fix.
0 commit comments