auto_factorize_columns: Intelligently convert character columns to factors in a data...

View source: R/data_manip_utils.R

auto_factorize_columnsR Documentation

Intelligently convert character columns to factors in a data frame

Description

For each column of a data frame, if it is a character vector with at least one non-unique value, convert that column to a factor. Character columns with no repeated values (e.g. sample IDs) will not be modified.

Usage

auto_factorize_columns(df)

Arguments

df

The data frame to operate on.

Value

df, possibly with some character columns replaced by factors

Examples


# Initially, both columns are character vectors
x <- data.frame(sample = letters, group = LETTERS[1:2], stringsAsFactors = FALSE)
sapply(x, class)

# This converts group, but not sample, into a factor
x2 <- auto_factorize_columns(x)
sapply(x2, class)


DarwinAwardWinner/rctutils documentation built on July 22, 2022, 5:19 a.m.