.BG
.VE $Header: /usr3/s/current/s/.help/RCS/subset,v 1.2 83/12/30 19:35:11 rab Exp $
.FN subset
.FN [
.FN ]
.TL
[ ]: Subsets of Data
.CS
data [expr]   # vector subscripts
data [expr1, expr2, ...]  # multi-dimensional array subscripts
.PP
.AG data
a matrix, array or vector structure.
Missing values (NAs) are allowed.
.AG expr
either a logical vector of same length as `data'
or an (integer) vector of subscripts, in which case the
subscripts must be all positive or all negative.  Positive
values select those elements; negative values select all
except those elements.
Missing values (NAs) are allowed if `expr' is logical.
.PP
For multi-dimensional data, `expri' should be a logical vector
of the same length as the extent of the `i'th subscript, or
an integer vector of subscripts for the `i'th dimension.
.PP
.RT
a vector of same mode as `data' containing either the
elements for which `expr' is TRUE (if `expr' is logical),
or the elements given by positive integer `expr',
or all elements other than those given by negative integer `expr'.
.EX
x[x!=999.999]  # x values not equal to 999.999

x[order(y)]   # sort x by increasing values of y

x[ \-c(1,3) ] # all but the first and third
.PP
If more than one `expri' is given,
then `data' must have exactly the same number of dimensions as there
are subscripts.
The first expression selects on the first
dimension, the second on the second, etc.  
.PP
All vector structures, including arrays, can appear with one subscript,
in which case the result is a vector.
.EX
A <- array(1:30, c(5,3,2) )   # array with dimension 5 x 3 x 2

A[1,1,1]   # a scalar, the first data value of A
A[1]       # the same

A[,1:2,]   # a (5,2,2) array

A[A>3]    # the vector 4:30
.KW builtin
.KW basic*
.KW manip
.WR
