recode_sex {growthcleanr} | R Documentation |
Recode binary sex variable for compatibility
Description
recode_sex
recodes a binary sex variable for a given source column in a data frame or data table.
Useful in transforming output from growthcleanr::cleangrowth() into a format suitable for growthcleanr::ext_bmiz().
Usage
recode_sex(
input_data,
sourcecol = "sex",
sourcem = "0",
sourcef = "1",
targetcol = "sex_recoded",
targetm = 1L,
targetf = 2L
)
Arguments
input_data |
a data frame or data table to be transformed. Expects a source column containing a binary sex variable. |
sourcecol |
name of sex descriptor column. Defaults to "sex" |
sourcem |
variable indicating "male" sex in input data. Defaults to "0" |
sourcef |
variable indicating "female" sex in input data. Defaults to "1" |
targetcol |
desired name of recoded sex descriptor column. Defaults to "sex_recoded" |
targetm |
desired name of recoded sex variable indicating "male" sex in output data. Defaults to 1 |
targetf |
desired name of recoded sex variable indicating "female" sex in output data. Defaults to 2 |
Value
Returns a data table with recoded sex variables.
Examples
# Run on given data
df <- as.data.frame(syngrowth)
# Run with all defaults
df_r <- recode_sex(df)
# Specify different targets
df_rt <- recode_sex(df, targetcol = "sexr", targetm = "Male", targetf = "Female")
# Specify different inputs
df_ri <- recode_sex(df_rt, sourcecol = "sexr", sourcem = "Male", sourcef = "Female")