mergePed: Merge two pedigrees

View source: R/mergePed.R

mergePedR Documentation

Merge two pedigrees

Description

This function merges two pedigrees, joining them at the indicated individuals.

Usage

mergePed(x, y, by = NULL, relabel = FALSE, ...)

Arguments

x, y

Two ped() objects.

by

The individuals to merge by. The most general form uses a named vector with entries of the form id.x = id.y (see Examples). If the vector is unnamed, it is assumed that the individuals have the same labels in both pedigrees. By default set to intersect(labels(x), labels(y)).

relabel

A logical, by default FALSE. If TRUE, relabel(..., "asPlot") is run on the merged pedigree before returning.

...

further arguments passed along to ped(), e.g. famid, validate and reorder.

Details

Some internal checks are done to ensure that merging individuals are compatible in terms of sex and parents.

If relabel = FALSE, some relabelling might still be performed in order to ensure unique labels for everyone. Specifically, this is the case if some ID labels occur in both x and y other than those given in the by argument. In such cases, the relevant members of y get a suffix .y.

Value

A ped object.

Author(s)

Magnus Dehli Vigeland

Examples


############
# Example 1: Merge 2 trios by fusing the fathers
x1 = x2 = nuclearPed()
x = mergePed(x1, x2, by = c("1" = "1"))
plot(x)


##################################
# Example 2: Double first cousins
##################################

# First cousins, whose fathers are brothers
y = cousinPed(degree = 1)

# Create two sisters
sisters = nuclearPed(2, sex = 2)

# Plot to see who is who: `plot(list(y, sisters))`

# Merge
z = mergePed(y, sisters, by = c("4" = 3, "6" = 4), relabel = TRUE)
plot(z)


pedtools documentation built on Nov. 5, 2025, 5:50 p.m.