char2factor {tidytlg}R Documentation

Convert character variable to a factor based off it's numeric variable counterpart.

Description

Convert character variable to a factor based off it's numeric variable counterpart.

Usage

char2factor(df, c_var, n_var)

Arguments

df

data frame.

c_var

character variable within the data frame.

n_var

numeric variable counter part within the data frame to control the levels.

Value

A factor.

Examples

df <- tibble::tribble(
  ~TRT01P, ~TRT01PN,
  "Placebo",   1,
  "Low Dose",  2,
  "High Dose", 3
  )

# alphabetical order
dplyr::arrange(df, TRT01P)

# change to factor with char2factor
df$TRT01P <- char2factor(df, "TRT01P", "TRT01PN")

# factor order
dplyr::arrange(df, TRT01P)

[Package tidytlg version 0.1.5 Index]