R/unwrapRows.R

Defines functions unwrapRows

Documented in unwrapRows

#' A function that unwraps a matrix and only keeps the first n elements.
#'
#' n can be either a constant (in which case it will be repeated), or a vector.
#'
#' @param mat A matrix
#' @param n The length of rows
#'
#' @return A vector
#' @export
unwrapRows <- function(mat, n) {
  n <- rep_len(n, nrow(mat))
  i <- 0
  out <- lapply(1:nrow(mat), function(i) {
    return(mat[i, 1:n[i]])
  })
  return(as.numeric(do.call(c, out)))
}
bocinsky/guedesbocinsky2018 documentation built on May 3, 2019, 8:59 p.m.