ys_factors: Convert columns to factors

View source: R/col_factor.R

ys_factorsR Documentation

Convert columns to factors

Description

This function works like ys_add_factors() with the difference that the original columns become factors (retaining the original column names) and the original columns are retained with a suffix. You can think of this as a more convenient form of ys_add_factors(..., .suffix = "").

Usage

ys_factors(data, spec, ..., .keep_values = TRUE, .suffix = "_v")

Arguments

data

the data set to modify

spec

a yspec object

...

unquoted column names for modification; passing nothing through ... will signal for all columns to be considered for factors

.keep_values

logical; if TRUE, value columns will be retained with a .suffix.

.suffix

a suffix to be added to original columns (holding values).

Details

Factor conversion will only take place on source columns that aren't already factors. That is, if a column in data is already a factor, it will be ignored. This means the function can be called multiple times on the same input data, but once a column is converted to factor, it will cannot be converted again in subsequent calls.

Value

The original data frame is returned with columns converted to factors and (possibly) additional columns storing values.

See Also

ys_add_factors()

Examples


library(dplyr)

spec <- ys_help$spec()
data <- ys_help$data()

data <- ys_factors(data, spec)

head(data, 5)

spec$EVID

count(data, EVID, EVID_v)


metrumresearchgroup/yspec documentation built on May 24, 2024, 12:48 a.m.