This utility function drops empty factor levels from target factors as well as converting them to factors from character variables.
Usage
epict_clean_factors(obs, vars = c())
Arguments
- obs
A
data.frame
with at least one character or factor variable.- vars
A character vector of variables. Defaults to empty.
Value
A data.table
with empty factors dropped and character vectors
transformed to factors as specified.
See also
Preprocessing functions
epict_check_obs()
,
epict_check_raw_obs()
,
epict_drop_na_ct()
,
epict_filter_ids()
,
epict_flag_spurious_obs()
,
epict_make_time_rel_to_first_uncensored()
,
epict_make_time_rel()
Examples
obs <- data.frame(
m = c("fa", "aefwe", "efe"),
c = factor(c("fa", "asas", "asa"), levels = c("fa"))
)
summary(obs)
#> m c
#> Length:3 fa :1
#> Class :character NA's:2
#> Mode :character
# Default without specifying variables
summary(epict_clean_factors(obs))
#> m c
#> Length:3 fa :1
#> Class :character NA's:2
#> Mode :character
# Specify variables
summary(epict_clean_factors(obs, vars = c("m", "c")))
#> m c
#> aefwe:1 fa :1
#> efe :1 NA's:2
#> fa :1