Learn R Programming

pedtools (version 2.8.1)

mergePed: Merge two pedigrees

Description

This function merges two ped objects, joining them at the indicated individuals. Only ped objects without marker data are supported.

Usage

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

Value

A ped object.

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.

Author

Magnus Dehli Vigeland

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.

Examples

Run this code

############
# Example 1
# A family trio where each parent have first cousin parents.
############

# Trio
x = nuclearPed(1)

# Add paternal family
pat = cousinPed(1, child = TRUE)
x = mergePed(x, pat, by = c("1" = "9"))

# Maternal family
mat = cousinPed(1, child = TRUE) |> swapSex("9")
x = mergePed(x, mat, by = c("2" = "9"))

# Relabel (Alternative: add `relabel = TRUE` in the previous call)
x = relabel(x, "asPlot")

plot(x)


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

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

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

# Plot to see who is who: `plotPedList(list(y, motherPed))`

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

Run the code above in your browser using DataLab