xmu_relevel_factors: Relabel Factor Columns in a Data Frame

View source: R/umxCLPM.R

xmu_relevel_factorsR Documentation

Relabel Factor Columns in a Data Frame

Description

This function modifies the levels of specified factor columns in a data.frame where the specified factor columns have potentially collapsed levels based on the criteria provided.

Levels that make up less than a specified proportion of total observations are collapsed into the previous level, providing that a minimum number of levels remains.

The levels of the remaining factor columns are synchronized with the updated levels of the first specified column. Variables named in 'cols' must be factors. Note too that prop uses e.g., .1 to stand for 10 percent.

Usage

xmu_relevel_factors(df, cols, prop = 0.1, min = 8)

Arguments

df

A data frame containing the factor columns to be modified.

cols

A character vector specifying the names of the factor columns to relabel.

prop

A numeric value indicating the minimum proportion of observations for a level (default = .1)

min

Integer bounding the minimum remaining number of levels (Default 8).

Value

data.frame with the same structure as the input

See Also

Other xmu internal not for end user: umxModel(), umxRenameMatrix(), umx_APA_pval(), umx_fun_mean_sd(), umx_get_bracket_addresses(), umx_make(), umx_standardize(), umx_string_to_algebra(), xmuHasSquareBrackets(), xmuLabel_MATRIX_Model(), xmuLabel_Matrix(), xmuLabel_RAM_Model(), xmuMI(), xmuMakeDeviationThresholdsMatrices(), xmuMakeOneHeadedPathsFromPathList(), xmuMakeTwoHeadedPathsFromPathList(), xmuMaxLevels(), xmuMinLevels(), xmuPropagateLabels(), xmuRAM2Ordinal(), xmuTwinSuper_Continuous(), xmuTwinSuper_NoBinary(), xmuTwinUpgradeMeansToCovariateModel(), xmu_CI_merge(), xmu_CI_stash(), xmu_DF_to_mxData_TypeCov(), xmu_PadAndPruneForDefVars(), xmu_bracket_address2rclabel(), xmu_cell_is_on(), xmu_check_levels_identical(), xmu_check_needs_means(), xmu_check_variance(), xmu_clean_label(), xmu_data_missing(), xmu_data_swap_a_block(), xmu_describe_data_WLS(), xmu_dot_make_paths(), xmu_dot_make_residuals(), xmu_dot_maker(), xmu_dot_move_ranks(), xmu_dot_rank_str(), xmu_extract_column(), xmu_get_CI(), xmu_lavaan_process_group(), xmu_make_TwinSuperModel(), xmu_make_bin_cont_pair_data(), xmu_make_mxData(), xmu_match.arg(), xmu_name_from_lavaan_str(), xmu_path2twin(), xmu_path_regex(), xmu_print_algebras(), xmu_rclabel_2_bracket_address(), xmu_safe_run_summary(), xmu_set_sep_from_suffix(), xmu_show_fit_or_comparison(), xmu_simplex_corner(), xmu_standardize_ACE(), xmu_standardize_ACEcov(), xmu_standardize_ACEv(), xmu_standardize_CP(), xmu_standardize_IP(), xmu_standardize_RAM(), xmu_standardize_SexLim(), xmu_standardize_Simplex(), xmu_start_value_list(), xmu_starts(), xmu_summary_RAM_group_parameters(), xmu_twin_add_WeightMatrices(), xmu_twin_check(), xmu_twin_get_var_names(), xmu_twin_make_def_means_mats_and_alg(), xmu_twin_upgrade_selDvs2SelVars()

Examples

df = data.frame(
    group = factor(c("A", "B", "B", "C", "D", "E", "E", "E")),
    score = c(10, 15, 15, 20, 25, 30, 30, 30)
)

# Relabel factor columns
df_releveled = xmu_relevel_factors(df, cols = c("group"), prop = 0.2, min=2)
df_releveled


tbates/umx documentation built on Dec. 14, 2024, 11:28 a.m.