The R Project SVN R

Rev

Rev 61168 | Rev 67599 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 61168 Rev 62899
Line 1... Line 1...
1
% File src/library/base/man/which.min.Rd
1
% File src/library/base/man/which.min.Rd
2
% Part of the R package, http://www.R-project.org
2
% Part of the R package, http://www.R-project.org
3
% Copyright 1995-2010 R Core Team
3
% Copyright 1995-2013 R Core Team
4
% Distributed under GPL 2 or later
4
% Distributed under GPL 2 or later
5
 
5
 
6
\newcommand{\CRANpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}}
6
\newcommand{\CRANpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}}
7
 
7
 
8
\name{which.min}
8
\name{which.min}
9
\alias{which.min}
9
\alias{which.min}
10
\alias{which.max}
10
\alias{which.max}
11
\title{Where is the Min() or Max() ?}
11
\title{Where is the Min() or Max() or first TRUE or FALSE ?}
12
\concept{argmin}
12
\concept{argmin}
13
\concept{argmax}
13
\concept{argmax}
14
\concept{index of minimum}
14
\concept{index of minimum}
15
\concept{index of maximum}
15
\concept{index of maximum}
-
 
16
\concept{index of first TRUE}
-
 
17
\concept{index of first FALSE}
16
\description{
18
\description{
17
  Determines the location, i.e., index of the (first) minimum or maximum
19
  Determines the location, i.e., index of the (first) minimum or maximum
18
  of a numeric vector.
20
  of a numeric (or logical) vector.
-
 
21
 
-
 
22
  For a logical vector \code{x}, \code{which.min(x)} and \code{which.max(x)}
-
 
23
  return the index of the first \code{FALSE} or \code{TRUE}, respectively.
19
}
24
}
20
\usage{
25
\usage{
21
which.min(x)
26
which.min(x)
22
which.max(x)
27
which.max(x)
23
}
28
}
Line 55... Line 60...
55
## it *does* work with NA's present, by discarding them:
60
## it *does* work with NA's present, by discarding them:
56
presidents[1:30]
61
presidents[1:30]
57
range(presidents, na.rm = TRUE)
62
range(presidents, na.rm = TRUE)
58
which.min(presidents) # 28
63
which.min(presidents) # 28
59
which.max(presidents) #  2
64
which.max(presidents) #  2
-
 
65
 
-
 
66
## Find the first occurrence, i.e. the first TRUE:
-
 
67
x <- rpois(10000, lambda = 10); x[sample.int(50, 20)] <- NA
-
 
68
## where is the first value >= 20 ?
-
 
69
which.max(x >= 20)
60
}
70
}
61
\keyword{utilities}
71
\keyword{utilities}