R/rowIQRs.R
rowIQRs.RdEstimates of the interquartile range for each row (column) in a matrix.
rowIQRs(x, rows = NULL, cols = NULL, na.rm = FALSE, ...,
useNames = TRUE)
colIQRs(x, rows = NULL, cols = NULL, na.rm = FALSE, ...,
useNames = TRUE)
iqr(x, idxs = NULL, na.rm = FALSE, ...)A vector indicating subset of rows to
operate over. If NULL, no subsetting is done.
A vector indicating subset of columns to
operate over. If NULL, no subsetting is done.
If TRUE, missing values are
excluded.
Additional arguments passed to rowQuantiles()
(colQuantiles()).
If TRUE (default), names
attributes of the result are set, otherwise not.
A vector indicating subset of elements to
operate over. If NULL, no subsetting is done.
Contrary to IQR, which gives
an error if there are missing values and na.rm = FALSE, iqr()
and its corresponding row and column-specific functions return
NA_real_.
set.seed(1)
x <- matrix(rnorm(50 * 40), nrow = 50, ncol = 40)
str(x)
#> num [1:50, 1:40] -0.626 0.184 -0.836 1.595 0.33 ...
# Row IQRs
q <- rowIQRs(x)
print(q)
#> [1] 1.1731306 1.0107162 1.6654064 1.2539423 1.3705467 1.6404858 1.6995732
#> [8] 1.3291742 1.6886054 1.2549506 0.9359126 1.0195589 1.4007595 1.2198987
#> [15] 1.0787055 1.4524548 1.2556678 1.6562935 0.9436753 1.5332922 1.0804972
#> [22] 1.3345150 1.3778290 1.2813150 1.1560162 1.2670159 1.6274822 1.0123151
#> [29] 1.3011232 0.9232206 1.3664274 1.6141894 1.3007675 1.3635105 1.1991735
#> [36] 1.1799147 1.5664136 1.1915430 1.3908429 1.2292913 1.3337325 1.1083987
#> [43] 1.1150356 1.3610511 1.9523920 1.1711522 1.8068631 1.4450980 1.7511271
#> [50] 1.1295912
q0 <- apply(x, MARGIN = 1, FUN = IQR)
stopifnot(all.equal(q0, q))
# Column IQRs
q <- colIQRs(x)
print(q)
#> [1] 1.100049 1.178648 0.916382 1.523818 1.233231 1.177970 1.248359 1.281653
#> [9] 1.305779 1.463096 1.121270 1.524690 1.262950 1.608730 1.937564 1.666534
#> [17] 1.370162 1.238580 1.341196 1.214581 1.610758 1.488645 1.361843 1.332965
#> [25] 1.244894 1.507090 1.172773 1.349565 1.511738 1.213386 1.241099 1.408363
#> [33] 1.050347 1.389932 1.806088 1.377805 1.241565 1.241594 1.234828 1.580717
q0 <- apply(x, MARGIN = 2, FUN = IQR)
stopifnot(all.equal(q0, q))