arrange in R
Sorting rows, ascending by default and descending on request.
library(dplyr)
runs <- tibble(
lang = c("r", "python", "sql", "go"),
stars = c(3L, 3L, 1L, NA_integer_),
tpm = c(96, 104, 79, 88)
)
print(arrange(runs, tpm))
print(arrange(runs, desc(stars), lang))
print(arrange(runs, stars))
print(slice_max(runs, tpm, n = 2))
print(slice_min(runs, tpm, n = 1))
How it works
desc()reverses one column's order.- Several columns break ties left to right.
- NA sorts last whichever direction you choose.
Keywords and builtins used here
arrangecdesclibraryprintslice_maxslice_mintibble
The run, in numbers
- Lines
- 13
- Characters to type
- 297
- Tokens
- 109
- Three-star pace
- 95 tpm
At the three-star pace of 95 tokens a minute, this run takes about 69 seconds.
Step 2 of 5 in Rows, step 6 of 27 in dplyr.