-
Notifications
You must be signed in to change notification settings - Fork 33
/
rowRanges.R
116 lines (108 loc) · 3.75 KB
/
rowRanges.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
###########################################################################/**
# @RdocFunction rowRanges
# @alias colRanges
# @alias rowMins
# @alias rowMaxs
# @alias colMins
# @alias colMaxs
#
# @title "Gets the range of values in each row (column) of a matrix"
#
# \description{
# @get "title".
# }
#
# \usage{
# @usage rowRanges
# @usage colRanges
# @usage rowMins
# @usage colMins
# @usage rowMaxs
# @usage colMaxs
# }
#
# \arguments{
# \item{x}{A @numeric NxK @matrix.}
# \item{rows, cols}{A @vector indicating subset of rows (and/or columns)
# to operate over. If @NULL, no subsetting is done.}
# \item{na.rm}{If @TRUE, @NAs are excluded first, otherwise not.}
# \item{dim.}{An @integer @vector of length two specifying the
# dimension of \code{x}, also when not a @matrix.}
# \item{mc.cores}{The number of cores to use, i.e. at most how many child
# threads will be run simultaneously.}
# \item{...}{Not used.}
# }
#
# \value{
# \code{rowRanges()} (\code{colRanges()}) returns a
# @numeric Nx2 (Kx2) @matrix, where
# N (K) is the number of rows (columns) for which the ranges are
# calculated.
#
# \code{rowMins()/rowMaxs()} (\code{colMins()/colMaxs()}) returns a
# @numeric @vector of length N (K).
# }
#
# @author "HB"
#
# \seealso{
# @see "rowOrderStats" and @see "base::pmin.int".
# }
#
# @keyword array
# @keyword iteration
# @keyword robust
# @keyword univar
#*/###########################################################################
rowRanges <- function(x, rows=NULL, cols=NULL, na.rm=FALSE, dim.=dim(x), mc.cores=1L, ...) {
dim. <- as.integer(dim.)
na.rm <- as.logical(na.rm)
.Call("rowRanges", x, dim., rows, cols, 2L, na.rm, TRUE, mc.cores, PACKAGE="matrixStats")
}
rowMins <- function(x, rows=NULL, cols=NULL, na.rm=FALSE, dim.=dim(x), mc.cores=1L, ...) {
dim. <- as.integer(dim.)
na.rm <- as.logical(na.rm)
.Call("rowRanges", x, dim., rows, cols, 0L, na.rm, TRUE, mc.cores, PACKAGE="matrixStats")
}
rowMaxs <- function(x, rows=NULL, cols=NULL, na.rm=FALSE, dim.=dim(x), mc.cores=1L, ...) {
dim. <- as.integer(dim.)
na.rm <- as.logical(na.rm)
.Call("rowRanges", x, dim., rows, cols, 1L, na.rm, TRUE, mc.cores, PACKAGE="matrixStats")
}
colRanges <- function(x, rows=NULL, cols=NULL, na.rm=FALSE, dim.=dim(x), mc.cores=1L, ...) {
dim. <- as.integer(dim.)
na.rm <- as.logical(na.rm)
.Call("colRanges", x, dim., rows, cols, 2L, na.rm, TRUE, mc.cores, PACKAGE="matrixStats")
}
colMins <- function(x, rows=NULL, cols=NULL, na.rm=FALSE, dim.=dim(x), mc.cores=1L, ...) {
dim. <- as.integer(dim.)
na.rm <- as.logical(na.rm)
.Call("colRanges", x, dim., rows, cols, 0L, na.rm, TRUE, mc.cores, PACKAGE="matrixStats")
}
colMaxs <- function(x, rows=NULL, cols=NULL, na.rm=FALSE, dim.=dim(x), mc.cores=1L, ...) {
dim. <- as.integer(dim.)
na.rm <- as.logical(na.rm)
.Call("colRanges", x, dim., rows, cols, 1L, na.rm, TRUE, mc.cores, PACKAGE="matrixStats")
}
############################################################################
# HISTORY:
# 2015-07-17 [DJ]
# o Provided multicore processing APIs.
# 2015-05-25 [DJ]
# o Supported subsetted computation.
# 2014-12-17 [HB]
# o CLEANUP: Made col- and rowRanges() plain R functions.
# 2014-11-16
# o SPEEDUP: Implemented in native code.
# 2013-07-28
# o SPEEDUP: Made (col|row)Mins() and (col|row)Maxs() faster.
# o BUG FIX: rowRanges(x) on an Nx0 matrix 'x' would give an error.
# Ditto for colRanges(x).
# 2009-02-01
# o BUG FIX: colRanges(x) would give an error if nrow(x) == 0.
# 2008-03-25
# o Since colOrderStats() cannot handle missing values we use the slower
# colRanges() for the case when na.rm=TRUE.
# o Added {row|col}{Min|Max}s().
# o Created {row|col}Ranges() for scratch. Handles NAs.
############################################################################