getGenAncestors: Counts number of generations of ancestors for one subject....

View source: R/pedigree.R

getGenAncestorsR Documentation

Counts number of generations of ancestors for one subject. Use recursion.

Description

Counts number of generations of ancestors for one subject. Use recursion.

Usage

getGenAncestors(ped, id, ngen = NULL)

Arguments

ped

data.frame with a pedigree and a column for the number of generations of each subject.

id

subject for which we want the number of generations.

ngen

number of generation

Value

a data frame object with the pedigree and generation of ancestors for subject id.

Examples

ped <- pedigree(sire = c(NA, NA, 1,  1, 4, 5),
                dam =  c(NA, NA, 2, NA, 3, 2),
                label = 1:6)
ped <- ped2DF(ped)
ped$id <- row.names(ped)
ped$generation <- NA
(tmp1 <- getGenAncestors(ped, id = 1))
(tmp2 <- getGenAncestors(ped, id = 4))
(tmp3 <- getGenAncestors(ped, id = 6))

# Test for correctness
stopifnot(tmp1$generation[1] == 0)
stopifnot(all(is.na(tmp1$generation[-1])))
stopifnot(all(tmp2$generation[c(1, 4)] == c(0, 1)))
stopifnot(all(is.na(tmp2$generation[-c(1, 4)])))
stopifnot(all(tmp3$generation == c(0, 0, 1, 1, 2, 3)))

pedigreeTools documentation built on Oct. 12, 2024, 9:07 a.m.