View source: R/match_col_class.R
match_col_class | R Documentation |
Given a specified class such as "numeric" or "character", gets the column indexes in a data frame for columns matching that class.
match_col_class(df, class_type)
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"). |
A vector of column indexes corresponding to columns with classes that match the specified class.
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.