Learn R Programming

umx (version 1.9.1)

umx_long2wide: Take a long twin-data file and make it wide (one family per row)

Description

umx_long2wide merges on famID, for an unlimited number of twinIDs. Note: this assumes if zygosity or any passalong variables are NA in the first family member, they are NA everywhere. i.e., it does not hunt for values that are present elsewhere to try and self-heal missing data.

Usage

umx_long2wide(data, famID = NA, twinID = NA, zygosity = NA,
  vars2keep = NA, passalong = NA)

Arguments

data

The original (long-format) data file

famID

The unique identifier for members of a family

twinID

The twinID. Typically 1, 2, 50 51, etc...

zygosity

Typically MZFF, DZFF MZMM, DZMM DZOS

vars2keep

= The variables you wish to analyse (these will be renamed with paste0("_T", twinID)

passalong

= Variables you wish to pass-through (keep, even though not twin vars)

Value

- dataframe in wide format

References

- https://github.com/tbates/umx, https://tbates.github.io

See Also

- merge

Other Data Functions: umxCovData, umxFactor, umxHetCor, umxPadAndPruneForDefVars, umx_as_numeric, umx_cont_2_quantiles, umx_cov2raw, umx_lower2full, umx_make_MR_data, umx_make_TwinData, umx_make_bin_cont_pair_data, umx_make_fake_data, umx_merge_CIs, umx_read_lower, umx_reorder, umx_residualize, umx_round, umx_scale_wide_twin_data, umx_scale, umx_swap_a_block, umx_wide2long, umx

Other Twin Modeling Functions: plot.MxModel, umxACESexLim, umxACE_cov_fixed, umxACEcov, umxACEv, umxACE, umxCF_SexLim, umxCP, umxGxE_window, umxGxE, umxIP, umxPlotACEcov, umxPlotCP, umxPlotGxE, umxPlotIP, umxReduceACE, umxSummaryACEcov, umxSummaryACEv, umxSummaryACE, umxSummaryCP, umxSummaryGxE, umxSummaryIP, umx_wide2long, umx, xmu_twin_check

Examples

Run this code
# NOT RUN {
# ================================================================
# = First we have to make a long format file to base the demo on =
# ================================================================
tmp = twinData[, -2]
tmp$twinID1 = 1
tmp$twinID2 = 2
long = umx_wide2long(data = tmp, sep = "")
#
# OK. Now to demo long2wide...
# Keeping all columns
wide = umx_long2wide(data= long, famID= "fam", twinID= "twinID", zygosity= "zygosity")
names(wide) # might want to rename vars like "part_T1" to "part" and delete T2 copy 
# Just keep bmi and wt
k = c("bmi", "wt")
wide = umx_long2wide(data= long, famID= "fam", twinID= "twinID", 
    zygosity= "zygosity", vars2keep = k)
names(wide)
# "fam" "twinID" "zygosity" "bmi_T1" "wt_T1" "bmi_T2" "wt_T2"
# Keep bmi and wt, and pass through 'cohort'
wide = umx_long2wide(data= long, famID= "fam", twinID= "twinID", zygosity= "zygosity", 
	vars2keep = k, passalong = "cohort")
# }

Run the code above in your browser using DataLab