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

View source: R/match_col_class.R

match_col_classR Documentation

Get column indexes of a given class in a data frame

Description

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

Usage

match_col_class(df, class_type)

Arguments

df

The data frame for which columns should be matched.

class_type

The type of class to match as a character string (e.g. "numeric", "integer", "logical", "character", "factor").

Value

A vector of column indexes corresponding to columns with classes that match the specified class.

Examples

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/jute documentation built on Jan. 11, 2023, 8:23 a.m.