operationareamat.R 4.14 KB
 1 2 3 4 5 6 7 ``````#' 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. #' `````` Ahmad Alkadri committed Jul 18, 2019 8 ``````#' @usage meanareamat(m, rowmin=1, rowmax, colmin=1, colmax) `````` 9 10 11 ``````#' #' @param m A matrix object #' `````` Ahmad Alkadri committed Jul 18, 2019 12 ``````#' @param rowmin The first row for subsetting. Default value is 1. `````` Ahmad Alkadri committed Jul 10, 2019 13 ``````#' `````` Ahmad Alkadri committed Jul 18, 2019 14 ``````#' @param rowmax The last row for subsetting. `````` Ahmad Alkadri committed Jul 10, 2019 15 ``````#' `````` Ahmad Alkadri committed Jul 18, 2019 16 ``````#' @param colmin The first column for subsetting. Default value is 1. `````` Ahmad Alkadri committed Jul 10, 2019 17 ``````#' `````` Ahmad Alkadri committed Jul 18, 2019 18 ``````#' @param colmax The last column for subsetting. `````` Ahmad Alkadri committed Jul 10, 2019 19 ``````#' `````` 20 21 22 23 24 25 ``````#' @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) `````` Ahmad Alkadri committed Jul 18, 2019 26 ``````meanareamat <- function(m, rowmin=1, rowmax, colmin=1, colmax){ `````` 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 `````` 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. #' `````` Ahmad Alkadri committed Jul 18, 2019 45 ``````#' @usage medianareamat(m, rowmin=1, rowmax, colmin=1, colmax) `````` 46 47 48 ``````#' #' @param m A matrix object #' `````` Ahmad Alkadri committed Jul 18, 2019 49 ``````#' @param rowmin The first row for subsetting. Default value is 1. `````` Ahmad Alkadri committed Jul 10, 2019 50 ``````#' `````` Ahmad Alkadri committed Jul 18, 2019 51 ``````#' @param rowmax The last row for subsetting. `````` Ahmad Alkadri committed Jul 10, 2019 52 ``````#' `````` Ahmad Alkadri committed Jul 18, 2019 53 ``````#' @param colmin The first column for subsetting. Default value is 1. `````` Ahmad Alkadri committed Jul 10, 2019 54 ``````#' `````` Ahmad Alkadri committed Jul 18, 2019 55 ``````#' @param colmax The last column for subsetting. `````` Ahmad Alkadri committed Jul 10, 2019 56 ``````#' `````` 57 58 59 60 61 62 ``````#' @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) `````` Ahmad Alkadri committed Jul 18, 2019 63 ``````medianareamat <- function(m, rowmin=1, rowmax, colmin=1, colmax){ `````` 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 `````` 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. #' `````` Ahmad Alkadri committed Jul 18, 2019 82 ``````#' @usage sdareamat(m, rowmin=1, rowmax, colmin=1, colmax) `````` 83 84 85 ``````#' #' @param m A matrix object #' `````` Ahmad Alkadri committed Jul 18, 2019 86 ``````#' @param rowmin The first row for subsetting. Default value is 1. `````` Ahmad Alkadri committed Jul 10, 2019 87 ``````#' `````` Ahmad Alkadri committed Jul 18, 2019 88 ``````#' @param rowmax The last row for subsetting. `````` Ahmad Alkadri committed Jul 10, 2019 89 ``````#' `````` Ahmad Alkadri committed Jul 18, 2019 90 ``````#' @param colmin The first column for subsetting. Default value is 1. `````` Ahmad Alkadri committed Jul 10, 2019 91 ``````#' `````` Ahmad Alkadri committed Jul 18, 2019 92 ``````#' @param colmax The last column for subsetting. `````` Ahmad Alkadri committed Jul 10, 2019 93 ``````#' `````` 94 95 96 97 98 99 ``````#' @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) `````` Ahmad Alkadri committed Jul 18, 2019 100 ``````sdareamat <- function(m, rowmin=1, rowmax, colmin=1, colmax){ `````` 101 102 103 104 105 106 107 108 109 110 `````` m_n <- m[rowmin:rowmax,colmin:colmax] sd_m <- sd(m_n) rm(m_n) return(sd_m) } `````` Ahmad Alkadri committed Jul 18, 2019 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 `````` #' 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) }``````