R/draw_sex.R

Defines functions draw_sex

Documented in draw_sex

#' Draw sex values randomly for a list of individuals
#'
#' Each individual has their sex drawn between male and female with equal probability.
#' Sex is encoded numerically following the convention for plink FAM files (see below).
#'
#' @param n The number of individuals.
#'
#' @return The length-`n` vector of integer sex assignments: `1L` corresponds to male, `2L` to female.
#'
#' @examples
#' draw_sex( 10 )
#' 
#' @seealso
#' Plink FAM format reference:
#' <https://www.cog-genomics.org/plink/1.9/formats#fam>
#'
#' @export
draw_sex <- function(n) {
    if ( missing( n ) )
        stop( '`n` is required!' )
    if ( n < 1 )
        stop( '`n >= 1` is required!' )
    return( sample( c(1L, 2L), n, replace = TRUE ) )
}

Try the simfam package in your browser

Any scripts or data that you put into this service are public.

simfam documentation built on Jan. 10, 2023, 1:06 a.m.