merge_multiple_lr_var: Merge multiple variables that have distinct left and right...

Description Usage Arguments Value Examples

View source: R/data_io.R

Description

The input is a data frame with multiple variables that have left and right aspects (to merge a single variable, use merge_lr_var). Call merge_lr_var for each variable to merge it. The input variables approach and base_var should be vectors of the same length (the number of variables to merge). sideLabels and sideLoc are as in [merge_lr_var], but are assumed to be the same for all variables (consequently, it is not possible to mix prefixing, "left_man_I1" and affixing, "man_I1_L"). Aside from these requirements, approach, baseVar, sideLabels, and sideLoc behave identically in [merge_multiple_lr_var] and [merge_lr_var].

Usage

1
merge_multiple_lr_var(input_df, base_var, side_loc, side_labels, approach)

Arguments

input_df

Original data frame to be manipulated.

base_var

The base variables to be merged (a vector the same length as approach)

side_loc

Character string identifying if side labels are at the "start" or "end" of the base variable name

side_labels

Character string of left and right labels (in that order; ex.: c('_L','_R')).

approach

The merging approaches to take (a vector the same length as baseVar)

Value

The merged data frame

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Call merge_multiple_lr_var to combine left and right variables per
# user-specified approach
ex_df <- data.frame(ord_var_L = c(0,NA,1,NA,2,NA),
                    ord_var_R = c(2,1,0,NA,2,1),
                    cont_var_L = c(10.5,NA,14.0,NA,8.7,NA),
                    cont_var_R = c(12.5,3.2,7.0,NA,8.7,1.0))

merged_df <- merge_multiple_lr_var(input_df = ex_df,
                                   base_var = c("ord_var","cont_var"),
                                   side_loc = "end",
                                   side_labels = c("_L","_R"),
                                   approach = c("lowest","left"))
print(merged_df)

MichaelHoltonPrice/yada documentation built on Sept. 19, 2021, 11:27 p.m.