Learn R Programming

umx (version 4.20.0)

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")

note: tvars is a shortcut for umx_paste_names

Usage

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

Value

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

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 = 1:2)

covNames

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

prefix

a string to prepend to each label, e.g "mean" -> "mean_age" "mean_sex"

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, tvars 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

namez() umx_explode_twin_names()

Other String Functions: umx_explode_twin_names(), umx_explode(), umx_grep(), umx_names(), umx_rot(), umx_str_chars(), umx_str_from_object(), umx_trim(), umx

Examples

Run this code
# 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 = "age", sep = "_T", prefix= "mean_")
tvars("IQ")

Run the code above in your browser using DataLab