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))
Run the code above in your browser using DataLab