pull: Column selection

Description Usage Arguments Value Author(s) Examples

View source: R/pull.R

Description

The function pull selects a column in a data frame and transforms it into a vector. This is useful to use it in combination with magrittr's pipe operator and dplyr's verbs.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
pull(.data, j)

pull_(.data, j)

## S3 method for class 'data.frame'
pull_(.data, j)

## S3 method for class 'matrix'
pull_(.data, j)

## S3 method for class 'list'
pull_(.data, j)

Arguments

.data

A tbl.

j

integer. The column to be extracted.

Value

A vector of length nrow(.data)

Author(s)

Adapted from Tommy O' Dell, see http://stackoverflow.com/a/24730843/3902976 on StackOverflow.

Examples

1
2
3
4
5
6
7
8
library(dplyr)
mtcars[["mpg"]]
mtcars %>% pull(mpg)

# more convenient than (mtcars %>% filter(mpg > 20))[[3L]]
mtcars %>%
  filter(mpg > 20) %>%
  pull(3)

lplyr documentation built on Nov. 17, 2017, 7:34 a.m.