as.matrix.ped: Convert 'ped' to matrix

View source: R/ped_convert.R

as.matrix.pedR Documentation

Convert ped to matrix

Description

Converts a ped object or a list of such to a numeric matrix using internal labels, with additional information attached as attributes.

Usage

## S3 method for class 'ped'
as.matrix(x, include.attrs = TRUE, ...)

## S3 method for class 'list'
as.matrix(x, include.attrs = TRUE, ...)

## S3 method for class 'pedList'
as.matrix(x, include.attrs = TRUE, ...)

restorePed(x, attrs = NULL, validate = TRUE)

Arguments

x

A ped object or a list of such. In restorePed: A numerical matrix.

include.attrs

a logical indicating if marker annotations and other info should be attached as attributes. See Value.

...

not used.

attrs

a list containing labels and other ped info compatible with x, in the format produced by as.matrix. If NULL, the attributes of x itself are used.

validate

a logical, forwarded to ped(). If FALSE, no checks for pedigree errors are performed.

Details

restorePed is the reverse of as.matrix.ped.

Value

For as.matrix: A numerical matrix with sum(pedsize(x)) rows. If include.attrs = TRUE the following attributes are attached (where applicable), allowing a single ped to be reproduced by restorePed:

  • FAMID the family identifier (a string)

  • LABELS the ID labels (a character vector)

  • UNBROKEN_LOOPS a logical indicating whether x has unbroken loops

  • LOOP_BREAKERS a numerical matrix, or NULL

  • markerattr a list containing the attributes of each marker

For lists, different family IDs are replaced by "", and attributes for loop breakers and founder inbreeding are not retained.

For restorePed: A ped object or a list of such.

Author(s)

Magnus Dehli Vigeland

See Also

ped()

Examples


x = relabel(nuclearPed(1), letters[1:3])

# To examplify the ped -> matrix -> ped trick, we show how to
# reverse the internal ordering of the pedigree.
m = as.matrix(x, include.attrs = TRUE)
m[] = m[3:1, ]

# Must reverse the labels also:
attrs = attributes(m)
attrs$LABELS = rev(attrs$LABELS)

# Restore ped:
y = restorePed(m, attrs = attrs)

# Of course a simpler way is use reorderPed():
z = reorderPed(x, 3:1)
stopifnot(identical(y, z))

as.matrix(singletons(1:2))

x = list(nuclearPed(), singleton("X")) |>
  addMarker(`1` = "1/2", X = "1/3", alleles = 1:3)
as.matrix(x)


pedtools documentation built on Nov. 5, 2026, 5:06 p.m.