Pulling values out in R
pull takes one column as a vector, which ends a pipeline.
library(dplyr)
runs <- tibble(
lang = c("r", "python", "sql"),
tpm = c(96, 104, 79)
)
best <- runs |>
filter(tpm > 80) |>
arrange(desc(tpm)) |>
pull(tpm)
print(best)
named <- pull(runs, tpm, name = lang)
print(named)
print(runs |> summarise(mean = mean(tpm)) |> pull(mean))
print(runs$lang[which.max(runs$tpm)])
How it works
pullis$that works in a pipe.- A named vector comes from
pull(name_column). - The native
|>pipe needs no package.
Keywords and builtins used here
arrangecdescfilterlibrarymeanprintpullsummarisetibble
The run, in numbers
- Lines
- 17
- Characters to type
- 314
- Tokens
- 109
- Three-star pace
- 100 tpm
At the three-star pace of 100 tokens a minute, this run takes about 65 seconds.
Step 1 of 2 in Ending a pipeline, step 25 of 27 in dplyr.