selectColumns: Select Columns from a Data Frame

View source: R/column.R

selectColumnsR Documentation

Select Columns from a Data Frame

Description

Select columns from a data frame. Stop with message if columns do not exist

Usage

selectColumns(
  x,
  columns = NULL,
  pattern = NULL,
  drop = (length(columns) == 1),
  do.stop = TRUE
)

Arguments

x

data frame

columns

vector of column names. If columns is of length 0 or NULL (default) or NA x is returned unchanged.

pattern

regular expression matching the names of the columns to be selected. Will only be evaluated if no explicit column names are given in columns.

drop

if TRUE and if only one column is to be selected the result is a vector (one dimensional) containing the values of the selected column and not a data frame. One dimension has been dropped then. See the help("[.data.frame"). The default is TRUE if length(columns) == 1, else FALSE.

do.stop

this flag controls whether the function stops (do.stop = TRUE) or not (do.stop = FALSE) if there are non-existing columns to be selected. If do.stop = FALSE only those columns are selected that actually exist

Value

data frame containing the columns of x that are specified in columns or x itself if columns is NULL or a vector containing the values of column value if columns is of length 1 and drop = TRUE (which is the default in this case).


KWB-R/kwb.utils documentation built on April 1, 2024, 7:12 a.m.