as.data.frame.ped: Convert ped to data frame

View source: R/ped_convert.R

as.data.frame.pedR Documentation

Convert ped to data frame

Description

Convert a ped object (or a list of such) to a data frame. The first columns are id, fid, mid and sex, followed by genotype columns.

Usage

## S3 method for class 'ped'
as.data.frame(x, ..., markers, sep = "/", missing = "-")

## S3 method for class 'pedList'
as.data.frame(x, ..., markers, sep = "/", missing = "-")

Arguments

x

A ped object or a list of such.

...

Further parameters.

markers

Vector of marker names or indices. By default, all markers are included.

sep

A single string to be used as allele separator in marker genotypes.

missing

A single string to be used for missing alleles.

Details

For lists of pedigrees, use as.data.frame.pedList() directly unless the list has class "pedList". The reason for this convention is to avoid conflicts with existing base::as.data.frame.list() method.

Note the difference between as.data.frame.ped() and as.matrix.ped(), which have different purposes. Conversion to a data frame is primarily intended for pretty printing. It uses correct labels for pedigree members and marker alleles, and pastes alleles to form nice-looking genotypes.

The matrix method, on the other hand, is a handy tool for manipulating the pedigree structure. It produces a numeric matrix, using the internal index labelling both for individuals and alleles, making it very fast. In addition, all necessary meta information (loop breakers, allele frequencies a.s.o) is kept as attributes, which makes it possible to recreate the original ped object.

Value

A data frame with 4 + nMarkers(x) columns.

See Also

as.matrix.ped()

Examples

x = nuclearPed() |> addMarker(`3` = "1/2", name = "M")
as.data.frame(x)
as.data.frame(x, markers = NULL)

# Ped list with compatible markers
y = list(x, singleton("X")) |> harmoniseMarkers()
as.data.frame.pedList(y)


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