Learn R Programming

poorman (version 0.2.0)

relocate: Select/relocate variables by name

Description

Choose or relocate variables from a data.frame. select() keeps only the variables you mention; relocate() keeps all the variables.

Usage

relocate(.data, ..., .before = NULL, .after = NULL)

select(.data, ...)

Arguments

.data

A data.frame.

...

The name(s) of the column(s) to select.

.before, .after

Destination of the columns selected by .... Supplying neither will move the columns to the left-hand side whereas supplying both will result in an error.

Value

A data.frame.

Useful functions

There are a number of special functions which are designed to work in select() and relocate():

Examples

Run this code
# NOT RUN {
select(mtcars, mpg:cyl)
select(mtcars, MilesPerGallon = mpg, Cylinders = cyl)
mtcars %>% select(mpg)
mtcars %>% select(!mpg, !cyl)
iris %>% select(contains("Petal"))

df <- as.data.frame(matrix(runif(100), nrow = 10))
df <- as.data.frame(df[c(3, 4, 7, 1, 9, 8, 5, 2, 6, 10)])
df %>% select(num_range("V", 4:6))

mtcars %>% relocate(ends_with("p"), .before = mpg)

# }

Run the code above in your browser using DataLab