mksib {networkR} | R Documentation |
Generate variables (or lists) of siblings from a file of ids of persons and their father and mother.
Description
The function generates for each person lists of maternal half-sibs, paternal half-sibs and full sibs. Optionally these are expanded to separate columns in a data.table.
Usage
mksib(obj, ns = 3, expand.vars = TRUE)
Arguments
obj |
A 3-column structure with column names |
ns |
Integer. The maximal no of sibs of each type to include in the result if sibling ids are required in separate columns. |
expand.vars |
Logical. Should the sibling ids be returned in separate
columns. If |
Details
There are no checks of persons being both mother and father, nor being its
own parent and incest checks are not performed. In other words, the
obj
is assumed to be sane, but possibly immoral.
Value
A data.table
with the columns of the obj
and columns
for ns
maternal, paternal and full sibs, named ms1
,
ms2
, ... ps1
, ps2
, ... fs1
,
fs2
.
If expand.vars=FALSE
there will instead be three columns of lists
named msibs
, psibs
and fsibs
.
Author(s)
Claus Thorn Ekstrøm, ekstrom@sund.ku.dk, Bendix Carstensen, b@bxc.dk
Examples
library( data.table )
id <- 1:12
pid <- c(NA, 1, 1, 1, NA, 23, 45, 5, 5, 7, 12, NA)
mid <- c(NA, NA, 2, 2, 12, NA, 46, 6, 6, 6, NA, 12)
indd <- data.table( id, mid, pid )
indata <- copy( indd )
indata
str( xx <- mksib( indata ) )
xx
zz <- mksib( indata, 2, e=FALSE )
zz