typestar

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

  1. pull is $ that works in a pipe.
  2. A named vector comes from pull(name_column).
  3. The native |> pipe needs no package.

Keywords and builtins used here

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.

Type this snippet

Step 1 of 2 in Ending a pipeline, step 25 of 27 in dplyr.

← Previous Next →