ourMELONS/R/simuloiAlleeli.R

31 lines
837 B
R
Raw Permalink Normal View History

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