ys_add_factors: Add factors to data set based on spec information

View source: R/col_factor.R

ys_add_factorsR Documentation

Add factors to data set based on spec information

Description

Add factors to data set based on spec information

Usage

ys_add_factors(
  .data,
  .spec,
  ...,
  .all = TRUE,
  .missing = NULL,
  .suffix = getOption("ys.fct.suffix", "_f")
)

yspec_add_factors(
  .data,
  .spec,
  ...,
  .all = TRUE,
  .missing = NULL,
  .suffix = getOption("ys.fct.suffix", "_f")
)

ys_make_factor(values, x, strict = TRUE, .missing = NULL)

yspec_make_factor(values, x, strict = TRUE, .missing = NULL)

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

.all

if TRUE then any column with a values attribute or where the make_factor field evaluates to TRUE will be added as a factor

.missing

a label to use assign to missing values NA when making the factor; keep this NULL (the default) to let missing values be handled naturally by factor()

.suffix

used to make the column name for the factors

values

a vector of values to convert to a factor

x

a ycol object

strict

if 'FALSE', then a factor will be returned for any 'values' type

Details

Note that .suffix can be chosen using option ys.fct.suffix. When the factor is made by base::factor(), the exclude argument is forced to character(0) so that nothing is excluded.

See Also

ys_factors()

Examples


spec <- load_spec_ex()

ys_make_factor(c(1,0,1,1,1,0), spec$SEX)

data <- data.frame(SEX = c(1,1,1,1,0,0,1,1), STUDY= c(202,100))

head(ys_add_factors(data, spec, SEX, STUDY))

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

head(ys_add_factors(data, spec))


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