ourMELONS/R/simuloiAlleeli.R

28 lines
833 B
R
Raw Normal View History

#' @title simuloiAlleeli
#' @description Simuloi populaation pop lokukseen loc alleelin.
#' @note This function is (only?) called by `simulateIndividuals()`. Therefore, exporting it is probably unnecessary.
#' @export
simuloiAlleeli <- function(allfreqs, pop, loc) {
2020-01-30 16:20:52 +01:00
if (length(dim(allfreqs)) == 0) {
freqs <- 1
} else {
2020-01-30 16:20:52 +01:00
if (length(dim(allfreqs)) == 3) { # distinguish between array and matrix
freqs <- allfreqs[, loc, pop]
} else {
freqs <- allfreqs[, loc]
}
}
2020-01-30 16:20:52 +01:00
# freqs <- ifelse(is.null(length(dim(allfreqs)), allfreqs[loc], 0)
# freqs <- switch() + 1,
# allfreqs[, loc],
# allfreqs[, loc, pop]
# )
cumsumma <- cumsum(freqs)
arvo <- runif(1)
isommat <- which(cumsumma > arvo)
all <- min(isommat)
return(all)
}