keep_pos {mclm} | R Documentation |
Subset an object by index
Description
These methods can be used to subset objects based on a numeric vector of indices.
Usage
keep_pos(x, pos, invert = FALSE, ...)
## S3 method for class 'fnames'
drop_pos(x, pos, ...)
## S3 method for class 'fnames'
keep_pos(x, pos, invert = FALSE, ...)
## S3 method for class 'freqlist'
drop_pos(x, pos, ...)
## S3 method for class 'freqlist'
keep_pos(x, pos, invert = FALSE, ...)
drop_pos(x, pos, ...)
## S3 method for class 'tokens'
drop_pos(x, pos, ...)
## S3 method for class 'tokens'
keep_pos(x, pos, invert = FALSE, ...)
## S3 method for class 'types'
drop_pos(x, pos, ...)
## S3 method for class 'types'
keep_pos(x, pos, invert = FALSE, ...)
Arguments
x |
An object of any of the classes for which the method is implemented. |
pos |
A numeric vector, the numbers in which identify positions (= indices)
of items in If the numbers are positive, then their values point to the items that are to be selected. If the numbers are negative, then their absolute values point to the items that are not to be selected. Positive and negative numbers must not be mixed. |
invert |
Logical. Whether the matches should be selected rather than the non-matches. |
... |
Additional arguments. |
Details
The methods keep_pos()
and drop_pos()
are part of a family of methods of
the mclm package used to subset different objects. The methods
starting with keep_
extract the items in x
based on the criterion specified
by the second argument. In contrast, the methods starting with drop_
exclude
the items that match the criterion in the same argument.
Calling a drop_
method is equivalent to calling its keep_
counterpart when
the invert
argument is TRUE
.
Value
Object of the same class as x
with the selected elements only.
See Also
Other subsetters:
brackets
,
keep_bool()
,
keep_re()
,
keep_types()
Examples
# For a 'freqlist' object --------------------
(flist <- freqlist("The man and the mouse.", as_text = TRUE))
keep_pos(flist, c(2, 3))
# For a 'types' object -----------------------
(tps <- as_types(letters[1:10]))
keep_pos(tps, c(1, 3, 5, 7, 9))
drop_pos(tps, c(1, 3, 5, 7, 9))
# For a 'tokens' object ----------------------
(tks <- as_tokens(letters[1:10]))
keep_pos(tks, c(1, 3, 5, 7, 9))
drop_pos(tks, c(1, 3, 5, 7, 9))