2019-12-17 10:53:59 +01:00
|
|
|
#' @title Compute rows
|
|
|
|
|
#' @description Individuals inds have been given. The function returns a vector,
|
|
|
|
|
#' containing the indices of the rows, which contain data from the individuals.
|
|
|
|
|
#' @param rowsFromInd rowsFromInd
|
|
|
|
|
#' @param inds matrix
|
|
|
|
|
#' @param ninds ninds
|
|
|
|
|
#' @export
|
|
|
|
|
computeRows <- function(rowsFromInd, inds, ninds) {
|
2020-01-30 12:11:19 +01:00
|
|
|
if (class(inds) != "matrix") inds <- as.matrix(inds)
|
2019-12-17 10:53:59 +01:00
|
|
|
if (identical(dim(inds), c(nrow(inds), 1L))) {
|
|
|
|
|
# Special treatment for vectors because R has col vectors by default,
|
|
|
|
|
# whereas Matlab has row vectors by default.
|
|
|
|
|
inds <- t(inds)
|
|
|
|
|
if (ninds == 0) return(matrix(, 1, 0))
|
|
|
|
|
}
|
|
|
|
|
rows <- inds[, rep(1, rowsFromInd)]
|
|
|
|
|
rows <- rows * rowsFromInd
|
2020-01-15 13:29:47 +01:00
|
|
|
miinus <- repmat(t((rowsFromInd - 1):0), c(ninds, 1))
|
2019-12-17 10:53:59 +01:00
|
|
|
rows <- rows - miinus
|
|
|
|
|
rows <- matrix(t(rows), c(1, rowsFromInd * ninds))
|
|
|
|
|
return(t(rows))
|
|
|
|
|
}
|
|
|
|
|
|