umx (version 1.9.1)

umx_paste_names: Concatenate base variable names with suffixes to create wide-format variable names (i.e twin-format)

Description

It's easier to work with base names, rather than the twice-as-long hard-to-typo list of column names. umx_paste_names adds suffixes to names so you can work with that nice short list. So, you provide bmi, and you get back fully specified family-wise names: c("bmi_T1", "bmi_T2")

Usage

umx_paste_names(varNames, sep = "", suffixes = 1:2, covNames = NULL,
  prefix = NULL)

Arguments

varNames

a list of base names, e.g c("bmi", "IQ")

sep

A string separating the name and the twin suffix, e.g. "_T" (default is "")

suffixes

a list of terminal suffixes differentiating the twins default = c("1", "2"))

covNames

a list of base names for covariates (sorted last in list), e.g c("age", "sex")

prefix

a string to pre=pend to each label, e.g c("mean_age", "mean_sex")

Value

  • vector of suffixed var names, i.e., c("v1_T1", "v2_T1", "v1_T2", "v2_T2", "cov_T1", "cov_T2")

Details

Method 1: Use complete suffixes

You can provide complete suffixes like "_T1" and "_T2". This has the benefit of being explicit and very general:

umx_paste_names(c("var1", "var2"), suffixes = c("_T1", "_T2"))

Note: for quick typing, vars is an alias for umx_paste_names

Method 2: Use sep and a suffix vector.

Alternatively, you can use sep to add a constant like "_T" after each basename, along with a vector of suffixes. This has the benefit of showing what is varying: This is then suffixed with e.g. "1", "2".

umx_paste_names(c("var1", "var2"), sep = "_T", suffixes = 1:2)

Working with covariates

If you are using umxACEcov, you need to keep all the covariates at the end of the list. Here's how:

umx_paste_names(c("var1", "var2"), cov = c("cov1"), sep = "_T", suffixes = 1:2)

note: in conventional twin models, the expCov matrix is T1 vars, followed by T2 vars. For covariates, you want T1vars, T2 vars, T1 covs, T2 covs. This is what covNames accomplishes.

References

See Also

Other Utility Functions: qm, umx_find_object, umx_msg, umx_names, umx_pb_note, umx_print, umx_rename, umx

Examples

Run this code
# NOT RUN {
# two styles doing the same thing: first is more general
umx_paste_names("bmi", suffixes = c("_T1", "_T2"))
umx_paste_names("bmi", sep = "_T", suffixes = 1:2)
varNames = umx_paste_names(c("N", "E", "O", "A", "C"), "_T", 1:2)
umx_paste_names(c("IQ", "C"), cov = c("age"), sep = "_T", suffixes = 1:2)
umx_paste_names(c("IQ", "C"), cov = c("age"), sep = "_T", prefix= "mean_")
# For quick-typing, tVars is an alias for umx_paste_names
tvars(c("IQ", "C"), cov = c("age"), sep = "_T", prefix= "mean_")
# }

Run the code above in your browser using DataLab