The R Project SVN R

Rev

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

Rev 61168 Rev 62656
Line 1... Line 1...
1
% File src/library/base/man/which.Rd
1
% File src/library/base/man/which.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
\name{which}
6
\name{which}
7
\alias{which}
7
\alias{which}
8
\alias{arrayInd}
8
\alias{arrayInd}
Line 22... Line 22...
22
   when \code{x} is an array?}
22
   when \code{x} is an array?}
23
 
23
 
24
 \item{ind}{integer-valued index vector, as resulting from
24
 \item{ind}{integer-valued index vector, as resulting from
25
   \code{which(x)}.}
25
   \code{which(x)}.}
26
 \item{.dim}{\code{\link{dim}(.)} integer vector}
26
 \item{.dim}{\code{\link{dim}(.)} integer vector}
27
 \item{.dimnames}{optional list of character \code{\link{dimnames}(.)},
27
 \item{.dimnames}{optional list of character \code{\link{dimnames}(.)}.
-
 
28
   If \code{useNames} is true, to be used for constructing dimnames for
-
 
29
   \code{arrayInd()} (and hence, \code{which(*, arr.ind=TRUE)}).
-
 
30
   If \code{\link{names}(.dimnames)} is not empty, these are used as
28
   of which only \code{.dimnames[[1]]} is used.}
31
   column names.  \code{.dimnames[[1]]} is used as row names.}
29
 \item{useNames}{logical indicating if the value of \code{arrayInd()}
32
 \item{useNames}{logical indicating if the value of \code{arrayInd()}
30
   should have (non-null) dimnames at all.}
33
   should have (non-null) dimnames at all.}
31
}
34
}
32
\value{
35
\value{
33
  If \code{arr.ind == FALSE} (the default), an integer vector with
36
  If \code{arr.ind == FALSE} (the default), an integer vector with
Line 54... Line 57...
54
which(ll)
57
which(ll)
55
which((1:12)\%\%2 == 0) # which are even?
58
which((1:12)\%\%2 == 0) # which are even?
56
which(1:10 > 3, arr.ind = TRUE)
59
which(1:10 > 3, arr.ind = TRUE)
57
 
60
 
58
( m <- matrix(1:12, 3, 4) )
61
( m <- matrix(1:12, 3, 4) )
59
which(m \%\% 3 == 0)
62
div.3 <- m \%\% 3 == 0
-
 
63
which(div.3)
60
which(m \%\% 3 == 0, arr.ind = TRUE)
64
which(div.3, arr.ind = TRUE)
61
rownames(m) <- paste("Case", 1:3, sep = "_")
65
rownames(m) <- paste("Case", 1:3, sep = "_")
62
which(m \%\% 5 == 0, arr.ind = TRUE)
66
which(m \%\% 5 == 0, arr.ind = TRUE)
63
 
67
 
64
dim(m) <- c(2, 2, 3); m
68
dim(m) <- c(2, 2, 3); m
65
which(m \%\% 3 == 0, arr.ind = FALSE)
69
which(div.3, arr.ind = FALSE)
66
which(m \%\% 3 == 0, arr.ind = TRUE)
70
which(div.3, arr.ind = TRUE)
67
 
71
 
68
vm <- c(m)
72
vm <- c(m)
69
dim(vm) <- length(vm) #-- funny thing with  length(dim(...)) == 1
73
dim(vm) <- length(vm) #-- funny thing with  length(dim(...)) == 1
-
 
74
which(div.3, arr.ind = TRUE)
-
 
75
\dontshow{
-
 
76
dimnames(m) <- list(X = c("U", "V"), Z = c("y","z"), three = LETTERS[1:3])
-
 
77
wm <- which(m \%\% 3 == 0, arr.ind = TRUE)
-
 
78
vn <- vm; dimnames(vn) <- list(LETTERS[1:12])
70
which(vm \%\% 3 == 0, arr.ind = TRUE)
79
wv <- which(vn \%\% 3 == 0, arr.ind = TRUE)
-
 
80
 
-
 
81
stopifnot(identical(wv, array(3L*(1:4), dim = c(4, 1),
-
 
82
                              dimnames = list(c("C", "F", "I", "L"), "dim1"))),
-
 
83
          identical(wm, array(c(1:2, 1:2, 2:1, 1:2, 1:3, 3L),
-
 
84
                              dim = 4:3,
-
 
85
                              dimnames = list(rep(c("U","V"),2),
-
 
86
                                              c("X", "Z", "three"))))
-
 
87
)
-
 
88
}%dont
71
}
89
}
72
\keyword{logic}
90
\keyword{logic}
73
\keyword{attribute}
91
\keyword{attribute}