R/chg_rownames.R

Defines functions chg_rownames

Documented in chg_rownames

#' Changes rownames of a matrix
#'
#' Function takes a vector containing names and a matrix and exchanges
#' the rownames of the matrix with the ones provided in the names vector.
#' Note that the row dimension of the matrix has to be equal to the length of the
#' names vector. The function was written to enable a rownames replacement in dplyr's pipe.
#'
#' @param matrix any matrix of dimension n*m
#' @param newnames a character vector of length n
#'
#' @return the given matrix with changed rownames
#' @export
#'
#' @examples
#' \dontrun{
#' matrix %>%
#'   chg_rownames(newnames)
#' }
chg_rownames <- function(matrix, newnames){
  rownames(matrix) <- newnames
  return(matrix)
}
ECSchmitt/PPClustA documentation built on Dec. 17, 2021, 5:36 p.m.