match_col_class: Get column indexes of a given class in a data frame

Description Usage Arguments Value Examples

Description

For a specified class such as "numeric" or "character", gets the column indexes in a data frame for columns matching the class.

Usage

1
match_col_class(df, class_type)

Arguments

df

data.frame: data frame for which columns should be matched.

class_type

character: type of class to match (e.g. "numeric", "integer", "logical", "character", "factor").

Value

integer: the vector of column indexes whose classes match the specified class.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
id    <- letters[1:3]
size  <- c(1.2, 3.5, 4.1)
num   <- c(1, 2, 3)
intgr <- c(1L, 2L, 3L)

df_no_fac <- data.frame(id, size, num, intgr, stringsAsFactors = FALSE)
match_col_class(df_no_fac, "character")

df_with_fac <- data.frame(id, size, num, intgr)
match_col_class(df_with_fac, "character")
match_col_class(df_with_fac, "factor")
match_col_class(df_with_fac, "numeric")
match_col_class(df_with_fac, "integer")

toniprice/jutebag documentation built on May 12, 2019, 4:39 a.m.