getSex {pedtools} | R Documentation |
Get or set the sex of pedigree members
Description
Functions for retrieving or changing the sex of specified pedigree members.
When used in pedigree constructions, swapSex()
is usually more convenient
than setSex()
, since it deals with spouses automatically.
Usage
getSex(x, ids = NULL, named = FALSE)
setSex(x, ids = NULL, sex)
swapSex(x, ids, verbose = TRUE)
Arguments
x |
A |
ids |
A vector identifying members of |
named |
A logical: return a named vector or not. |
sex |
A numeric vector with entries 1 (= male), 2 (= female) or 0 (=
unknown). If |
verbose |
A logical: Verbose output or not. |
Details
To set unknown sex, use setSex(x, ids, sex = 0)
. Note that if a nonfounder
has unknown sex the pedigree cannot be plotted in the usual way, only with
plot(x, arrows = TRUE)
.
Value
-
getSex(x, ids)
returns an integer vector of the same length asids
, with entries 0 (unknown), 1 (male) or 2 (female). -
setSex(x, ids, sex)
returns a ped object similar tox
, but where the sex ofids
is set according to the entries ofsex
-
swapSex(x, ids)
returns a ped object identical tox
, but where the sex ofids
(and their spouses) are swapped (1 <-> 2). Individuals of unknown sex are ignored.
See Also
Examples
x = nuclearPed(father = "fa", mother = "mo", children = "ch")
stopifnot(all.equal(
getSex(x, named = TRUE),
c(fa = 1, mo = 2, ch = 1)
))
# Make child female
setSex(x, ids = "ch", sex = 2)
# Same, using a named vector
setSex(x, sex = c(ch = 2))
# Same, using a function (setting all leaves to be female)
setSex(x, ids = leaves, sex = 2)
# swapSex() deals with spouses automatically
swapSex(x, ids = "fa")
# setting/getting sex in a pedlist
y = singletons(id = 1:3, sex = c(2,1,1))
sx = getSex(y, named = TRUE)
y2 = setSex(y, sex = sx)
stopifnot(identical(y, y2))