DescTools (version 0.99.8.1)

WhichFlags: Get the Flags, Factors or Numerics of a data.frame

Description

Returns a vector with the names of the columns with the the specific property. WhichFlags returns the dichotomous columns, WhichFactors the factors, WhichNumerics all the numeric columns.

Usage

WhichFlags(d.frm)
WhichFactors(d.frm)
WhichNumerics(d.frm, type = c("all", "numeric", "integer"), excl.flags = FALSE)
WhichCharacters(d.frm)

Arguments

d.frm
data.frame whose elements should be listed.
type
type of numeric variables, defaults to "all". This is only used by WhichNumerics().
excl.flags
logical. Only used by WhichNumerics. Should flags be excluded or not. Default is FALSE, meaning flags will be included if they are numerics.

Value

  • a character vector with the names of the specific columns

Details

WhichFlags returns all apparently dichotomous columns, like logicals, integers and numerics with exactly 2 unique values or factors with 2 levels. WhichFactors returns all factors and ordered factors. WhichNumerics returns all numeric columns. Whether integers should be included or not can be defined by type. Default is "all". WhichCharacters returns the names of all character vectors in a data.frame. The functions yield the names of the variables. Use match to get the positions and %in% to get and boolean index vector (see examples).

See Also

class, mode

Examples

Run this code
data(d.pizza)

WhichFlags(d.pizza)
sapply(d.pizza[,WhichFlags(d.pizza)], class)

WhichFactors(d.pizza)
sapply(d.pizza[,WhichFactors(d.pizza)], class)

WhichNumerics(d.pizza)
WhichNumerics(d.pizza, type="numeric")
WhichNumerics(d.pizza, type="integer")


# get the positions
match(WhichNumerics(d.pizza), names(d.pizza))

# get an index vector
names(d.pizza) %in% WhichNumerics(d.pizza)

Run the code above in your browser using DataLab