order_cols: Re-order columns of a data frame

Description Usage Arguments Details Value Note Author(s) Examples

Description

order_cols takes in a data frame and reorders the columns specified by .... If front is TRUE specified columns are placed before unspecified ones, otherwise they are after unspecified columms.

Usage

1
order_cols(df, ..., front = TRUE)

Arguments

df

a data frame

...

unquoted column names in df

front

a logical value. Should ... be placed before unspecified columns?

Details

If all columns in df are specified, df is returned with columns in that order.

Value

df with its columns reordered

Note

See order_cols_q for a quoted version.

Author(s)

Sven Halvorson (svenedmail@gmail.com)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# We'll demonstrate reorder here
library("dplyr")
df = data.frame(a = 1:4,
                b = letters[4:7],
                c = rnorm(n = 4),
                d = rchisq(n = 4, df = 3),
                e = c("Salty", "Sweet", "Subtle", "Sweaty"),
                stringsAsFactors = FALSE)
df
order_cols(df, d, e)
order_cols(df, a, b, front = FALSE)

# Use with pipes
library("dplyr")
df 
  filter(nchar(e)>5) 
  order_cols(e,a)

svenhalvorson/SvenSFPS documentation built on May 21, 2019, 11:42 a.m.