File: rowMedians.Rd

package info (click to toggle)
r-bioc-biobase 2.42.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,000 kB
  • sloc: ansic: 711; makefile: 3; sh: 3
file content (60 lines) | stat: -rw-r--r-- 1,644 bytes parent folder | download | duplicates (6)
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
\name{rowMedians}
\alias{rowMedians}
\alias{rowMedians,matrix-method}
\alias{rowMedians,ExpressionSet-method}

\title{Calculates the median for each row in a matrix}

\description{
  Calculates the median for each row in a matrix.
}

\usage{rowMedians(x, na.rm=FALSE, ...)}

\arguments{
 \item{x}{A \code{\link[base]{numeric}} NxK \code{\link[base]{matrix}}.}
 \item{na.rm}{If \code{\link[base:logical]{TRUE}},
   \code{\link[base]{NA}}s are excluded first, otherwise not.}
 \item{...}{Not use.}
}

\value{
  Returns a \code{\link[base]{numeric}} \code{\link[base]{vector}} of
  length N.
}

\section{Missing values}{
  Missing values are excluded before calculating the medians.
}

\details{
  The implementation of \code{rowMedians()}
  is optimized for both speed and memory.
  To avoid coercing to \code{\link[base]{double}}s (and hence memory
  allocation), there is a special implementation for
  \code{\link[base]{integer}} matrices.  That is, if \code{x} is an
  \code{\link[base]{integer}} \code{\link[base]{matrix}}, then 
  \code{rowMedians(as.double(x))} would require three times the memory
  of \code{rowMedians(x)}, but all this is avoided.
}

\author{Henrik Bengtsson}

\seealso{
  See \code{rowMeans()} in \code{\link[base]{colSums}}().
}

\examples{
set.seed(1)
x <- rnorm(n=234*543)
x[sample(1:length(x), size=0.1*length(x))] <- NA
dim(x) <- c(234,543)
y1 <- rowMedians(x, na.rm=TRUE)
y2 <- apply(x, MARGIN=1, FUN=median, na.rm=TRUE)
stopifnot(all.equal(y1, y2))

x <- cbind(x1=3, x2=c(4:1, 2:5))
stopifnot(all.equal(rowMeans(x), rowMedians(x)))
}

\keyword{manip}