Learn R Programming

oaii (version 0.5.0)

df_order_by_col: Sort data.frame by column name

Description

Sort data.frame by column name

Usage

df_order_by_col(df, col, decreasing = FALSE, on_missing_col = "warn")

Value

Modified input data.frame

Arguments

df

data.frame, input data.frame

col

string, column name as sort source

decreasing

flag, should the sort order be increasing or decreasing?

on_missing_col

string, behavior for missing column(s): "warn" - log warning, "skip" - skip missing column(s), "stop" - throw error

Examples

Run this code
df <- data.frame(
  a = c("a", "b", "c"),
  b = c(1, 3, 2),
  c = c(3, 2, 1)
)
df_order_by_col(df, "b", decreasing = TRUE)
df_order_by_col(df, "c")

Run the code above in your browser using DataLab