factor2: Factors

View source: R/factor2.R

factor2R Documentation

Factors

Description

Fancy copy of the base function factor.

as_factor: haven_labelled zu factor

cut_bmi

BMI: WHO (kg/m2)

Very severely underweight 15 Severely underweight 15-16 Underweight 16-18.5 Normal (healthy weight) 18.5-25 Overweight 25-30 Obese Class I (Moderately obese) 30-35 Obese Class II (Severely obese) 35-40 Obese Class III (Very severely obese) 40

Usage

factor2(
  x,
  ...,
  levels,
  labels,
  exclude = NA,
  ordered = is.ordered(x),
  nmax = NA,
  add.na = FALSE
)

add_NA(x, na.string = "n.a.")

as_factor(x, ...)

cut_bmi(
  x,
  breaks = c(-Inf, 15, 16, 18.5, 25, 30, 35, 40, Inf),
  labels = c("Very severely underweight", "Severely underweight", "Underweight",
    "Normal", "Overweight", "Obese Class I", "Obese Class II", "Obese Class III"),
  n = 4
)

reorder2(
  x,
  X,
  ...,
  decreasing = TRUE,
  last = NULL,
  threshold = NULL,
  threshold.na.strings = "Other",
  rev = FALSE
)

Arguments

x

vector

...

levels and labels male = 1, female = 0, 'div inter' = 3, other = 2

levels, labels, exclude, ordered, nmax

an die Funktion factor

add.na

should NA be included

na.string

replacement for NA

breaks

number. breaks = c(-Inf, 15, 16, 18.5, 25, 30, 35, 40, Inf), labels = c( "Very severely underweight", "Severely underweight", "Underweight", "Normal", "Overweight", "Obese Class I", "Obese Class II", "Obese Class III" )

n

anzahl der BMI-Kategorien default = 4 Underweight, Normal, Overweight, Obese Class I

X

an reorder x => an atomic vector, usually a factor X => a vector of the same length as x, whose subset of values for each unique level of x determines the eventual order of that level.

decreasing

an ordere logical

last

character

threshold, threshold.na.strings

Anzahl an minimalen Nennungen

rev

logical. Reverse

Details

as_factor, factor2, cut_bmi, reorder2, relevel2, add_NA

Value

factor

Examples


x <- c(1, 0, 0, 0, 1, 1, 0, 3, 2, 2)
factor2(x)
factor2(x, levels = 1:0)
factor2(x, labels = c("m", "f", "d"))
factor2(x, male = 1, female = 0, 'div inter' = 3, other = 2)
factor2(x, 0:3)
factor2(x, 0:3, c("m", "f", "d", "o"))

table(cut_bmi(c(10, 15, 16, 18.5, 25, 30, 35, 40, 45)))
table(cut_bmi(c(10, 15, 16, 18.5, 25, 30, 35, 40, 45), n=4))
table(cut_bmi(c(10, 15, 16, 18.5, 25, 30, 35, 40, 45), n=5))
table(cut_bmi(c(10, 15, 16, 18.5, 25, 30, 35, 40, 45), n=6))


 x <-
c(
  rep(1, 21),rep(2, 120),rep(3, 28),rep(4, 4),rep(5, 56),
  rep(6, 2),rep(7, 92),rep(8, 42),rep(9, 74),rep(10, 20)
)

x <- factor(x, 1:10, letters[1:10])
table(x)
table(reorder2(x))
table(reorder2(x, threshold = 30))
#Reverse Elements
table(reorder2(x, rev = TRUE))

stp4/stp25tools documentation built on Feb. 27, 2025, 11:14 p.m.