pull( )

Pull out a column as a vector. pull() is from the dplyr package, which is part of the tidyverse.

Required Library

install.packages("tidyverse")
library(tidyverse)

Syntax

# Pipe style
df %>% pull(column)

# Non-pipe style
pull(df, column)

pull() extracts one column from a data frame or tibble and returns it as a vector. It works a bit like using $ to extract one column, but it fits more naturally inside a pipe.

df %>% pull(column) %>% mean()

Because pull() returns a vector, you can use the result in calculations right away.

Use pull() when you want the values from one column, not the full data frame. It is handy before calculations, summaries, or printing a column as a vector. Unlike select(), which keeps columns in a data frame, pull() returns just the values as a vector. That makes it a good choice when you want to use the result in a calculation.

Examples

Pull one column as a vector
Use pulled values in a calculation
Pull values for a quick comparison

Argument Overview

Required arguments must be included when using a function while optional arguments can be included on demand.

.data data frame | tibble Required

The data frame to pull a column from. In a pipe (%>%), this is passed automatically from the left-hand side.

tablet_weights %>% pull(weight_mg)

Data Types: data.frame | tibble

var — column to extract column name | position Optional

The column to extract. You can use a column name or a numeric position. If omitted, pull() uses the last column.

pull(tablet_weights, weight_mg)
pull(tablet_weights, 3)

Data Types: column name or integer position · Default: last column

name — column to use for names column name | position Optional

If you want the output vector to have names, supply a second column to use as the names. If omitted, the returned vector is unnamed.

tablet_weights %>% pull(weight_mg, name = tablet_id)

Data Types: column name or integer position · Default: NULL