mutate in R
Adding or replacing columns, computed from the ones already there.
library(dplyr)
runs <- tibble(chars = c(1820, 1980), seconds = c(60, 45))
print(mutate(runs,
wpm = chars / 5 / (seconds / 60),
fast = wpm > 80))
print(mutate(runs, cps = chars / seconds, .before = 1))
print(mutate(runs, wpm = chars / 5, .keep = "used"))
print(transmute(runs, minutes = seconds / 60))
How it works
- A new column can use a column defined earlier in the same call.
.beforeand.afterplace it without a separate relocate..keepcontrols which of the old columns survive.
Keywords and builtins used here
clibrarymutateprinttibbletransmute
The run, in numbers
- Lines
- 11
- Characters to type
- 303
- Tokens
- 99
- Three-star pace
- 95 tpm
At the three-star pace of 95 tokens a minute, this run takes about 63 seconds.
Step 1 of 4 in New columns, step 10 of 27 in dplyr.