Skip to content

Commit 79ffa8b

Browse files
indent code block
1 parent 438619b commit 79ffa8b

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

NEWS.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@
2020

2121
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=`.
2222

23-
```r
24-
d = data.table(id1=rep(1:2, each=3L), id2=letters[c(4:3,5L,3:5)], v1=1:6)
25-
dcast(d, id1 ~ factor(id2))
26-
# id1 c d e
27-
# 1: 1 2 1 3
28-
# 2: 2 4 5 6
29-
dcast(d, id1 ~ fctr(id2))
30-
# id1 d c e
31-
# 1: 1 1 2 3
32-
# 2: 2 5 4 6
33-
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-
```
23+
```r
24+
d = data.table(id1=rep(1:2, each=3L), id2=letters[c(4:3,5L,3:5)], v1=1:6)
25+
dcast(d, id1 ~ factor(id2))
26+
# id1 c d e
27+
# 1: 1 2 1 3
28+
# 2: 2 4 5 6
29+
dcast(d, id1 ~ fctr(id2))
30+
# id1 d c e
31+
# 1: 1 1 2 3
32+
# 2: 2 5 4 6
33+
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+
```
4242

4343
### BUG FIXES
4444

0 commit comments

Comments
 (0)