#' Function for getting the mean value of an area on a matrix. #' #' @description A function for calculating the mean value of an area of a matrix. #' For example if we want to get the mean value of part of a 10x10 matrix, starting from #' 2nd column, 1st row to 3rd row, 5th column, we'll get the values of this smaller matrix #' (3x4 to be precise) and then we'll calculate the mean of all of them. #' #' @usage meanareamat(m, rowmin=1, rowmax, colmin=1, colmax) #' #' @param m A matrix object #' #' @param rowmin The first row for subsetting. Default value is 1. #' #' @param rowmax The last row for subsetting. #' #' @param colmin The first column for subsetting. Default value is 1. #' #' @param colmax The last column for subsetting. #' #' @return The mean value of the subsetted area of matrix m #' #' @examples #' m <- matrix(rnorm(100, mean = 0, sd = 1), nrow = 10, ncol = 10) #' meanarea <- meanareamat(m, rowmin = 1, rowmax = 3, colmin = 2, colmax = 5) meanareamat <- function(m, rowmin=1, rowmax, colmin=1, colmax){ m_n <- m[rowmin:rowmax,colmin:colmax] mean_m <- mean(m_n) rm(m_n) return(mean_m) } #' Function for getting the median value of an area on a matrix. #' #' @description A function for calculating the median value of an area of a matrix. #' For example if we want to get the median value of part of a 10x10 matrix, starting from #' 2nd column, 1st row to 3rd row, 5th column, we'll get the values of this smaller matrix #' (3x4 to be precise) and then we'll calculate the median of all of them. #' #' @usage medianareamat(m, rowmin=1, rowmax, colmin=1, colmax) #' #' @param m A matrix object #' #' @param rowmin The first row for subsetting. Default value is 1. #' #' @param rowmax The last row for subsetting. #' #' @param colmin The first column for subsetting. Default value is 1. #' #' @param colmax The last column for subsetting. #' #' @return The median value of the subsetted area of matrix m #' #' @examples #' m <- matrix(rnorm(100, mean = 0, sd = 1), nrow = 10, ncol = 10) #' medianarea <- medianareamat(m, rowmin = 1, rowmax = 3, colmin = 2, colmax = 5) medianareamat <- function(m, rowmin=1, rowmax, colmin=1, colmax){ m_n <- m[rowmin:rowmax,colmin:colmax] median_m <- median(m_n) rm(m_n) return(median_m) } #' Function for getting the standard deviation value of an area on a matrix. #' #' @description A function for calculating the standard deviation value of an area of a matrix. #' For example if we want to get the standard deviation value of part of a 10x10 matrix, starting from #' 2nd column, 1st row to 3rd row, 5th column, we'll get the values of this smaller matrix #' (3x4 to be precise) and then we'll calculate the standard deviation of all of them. #' #' @usage sdareamat(m, rowmin=1, rowmax, colmin=1, colmax) #' #' @param m A matrix object #' #' @param rowmin The first row for subsetting. Default value is 1. #' #' @param rowmax The last row for subsetting. #' #' @param colmin The first column for subsetting. Default value is 1. #' #' @param colmax The last column for subsetting. #' #' @return The standard deviation value of the subsetted area of matrix m #' #' @examples #' m <- matrix(rnorm(100, mean = 0, sd = 1), nrow = 10, ncol = 10) #' sdarea <- sdareamat(m, rowmin = 1, rowmax = 3, colmin = 2, colmax = 5) sdareamat <- function(m, rowmin=1, rowmax, colmin=1, colmax){ m_n <- m[rowmin:rowmax,colmin:colmax] sd_m <- sd(m_n) rm(m_n) return(sd_m) } #' Function to subset a matrix. #' #' @description A function for subsetting a matrix. #' #' @usage subsetmat(m, rowmin=1, rowmax, colmin=1, colmax) #' #' @param m A matrix object #' #' @param rowmin The first row for subsetting. Default value is 1. #' #' @param rowmax The last row for subsetting. #' #' @param colmin The first column for subsetting. Default value is 1. #' #' @param colmax The last column for subsetting. #' #' @return The standard deviation value of the subsetted area of matrix m #' #' @examples #' m <- matrix(rnorm(100, mean = 0, sd = 1), nrow = 10, ncol = 10) #' m_part <- subsetmat(m, rowmin = 1, rowmax = 3, colmin = 2, colmax = 5) subsetmat <- function(m, rowmin=1, rowmax, colmin=1, colmax){ m_n <- m[rowmin:rowmax,colmin:colmax] return(m_n) }