pull: Pull out a single variable

Description Usage Arguments Examples

Description

This works like [[ for local data frames, and automatically collects before indexing for remote data tables.

Usage

1
pull(.data, var = -1)

Arguments

.data

A table of data

var

A variable specified as:

  • a literal variable name

  • a positive integer, giving the position counting from the left

  • a negative integer, giving the position counting from the right.

The default returns the last column (on the assumption that's the column you've created most recently).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
mtcars %>% pull(-1)
mtcars %>% pull(1)
mtcars %>% pull(cyl)

# Also works for remote sources
if (requireNamespace("dbplyr", quietly = TRUE)) {
df <- dbplyr::memdb_frame(x = 1:10, y = 10:1, .name = "pull-ex")
df %>%
  mutate(z = x * y) %>%
  pull()
}

YTLogos/dplyr documentation built on May 20, 2019, 1:44 p.m.