Learn R Programming

dplyr (version 0.7.2)

select_var: Select variable

Description

This function powers pull() and various functions of the tidyr package. It is similar to select_vars() but returns only one column name and has slightly different semantics: it allows negative numbers to select columns from the end.

Usage

select_var(vars, var = -1)

Arguments

vars

A character vector of existing column names.

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).

This argument is taken by expression and supports quasiquotation (you can unquote column names and column positions).

Value

The selected column name as an unnamed string.

See Also

pull(), select_vars()

Examples

Run this code
# NOT RUN {
# It takes its argument by expression:
select_var(letters, c)

# Negative numbers select from the end:
select_var(letters, -3)

# You can unquote variables:
var <- 10
select_var(letters, !! var)
# }

Run the code above in your browser using DataLab