as.matrix.ped {pedtools}R Documentation

Convert ped to matrix

Description

Converts a ped object to a numeric matrix using internal labels, with additional info necessary to recreate the original ped attached as attributes.

Usage

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

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

Arguments

x

a ped object. 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 pedsize(x) rows. If include.attrs = TRUE the following attributes are added to the matrix, allowing x to be exactly reproduced by restorePed:

For restorePed: A ped object.

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


[Package pedtools version 2.6.0 Index]