fact_to_frac: swap each occurrence of a factor with a level-specific number...

Description Usage Arguments Value Author(s) References Examples

View source: R/fact_to_frac.R

Description

A factor is provided in the 1st argument. By default (i.e., "frac = NULL") equally-spaced fractions descending from 1 to 0 are returned with the number of distinct fractions equal to the number of levels of the factor (e.g., a three-level factor will have distinct values 1, 0.5, 0 returned). If there is only one level in "fact", a vector of "1" values is returned. If a numeric vector "frac" with length equal to the number of levels in "fact" is provided, then the ordered values of "frac" are substituted in for the matching values of "fact" (see the example).

Usage

1

Arguments

fact

a factor

frac

a numeric vector with length equal to the number of levels of fact.

Value

a numeric vector with each instance of "fact" swapped out for its matching "frac" component.

Author(s)

Bill Forrest <forrest@gene.com>

Bill Forrest forrest@gene.com

References

www.r-project.org

Examples

1
2
3
4
 animal <- factor(c('ant','bird','cat','dog','emu','cat','bird'))
 animal_score <- c(1, 0.6, 0.2, 0.1, 0)
 maeve:::fact_to_frac( animal )
 maeve:::fact_to_frac( animal, animal_score )

wfforrest/maeve documentation built on Jan. 1, 2021, 12:47 p.m.