keep_bool | R Documentation |
These methods can be used to subset objects based on a logical vector.
keep_bool(x, bool, invert = FALSE, ...) drop_bool(x, bool, ...) ## S3 method for class 'fnames' drop_bool(x, bool, ...) ## S3 method for class 'fnames' keep_bool(x, bool, invert = FALSE, ...) ## S3 method for class 'freqlist' drop_bool(x, bool, ...) ## S3 method for class 'freqlist' keep_bool(x, bool, invert = FALSE, ...) ## S3 method for class 'tokens' drop_bool(x, bool, ...) ## S3 method for class 'tokens' keep_bool(x, bool, invert = FALSE, ...) ## S3 method for class 'types' drop_bool(x, bool, ...) ## S3 method for class 'types' keep_bool(x, bool, invert = FALSE, ...)
x |
An object of any of the classes for which the method is implemented. |
bool |
A logical vector of the same length as |
invert |
Logical. Whether the matches should be selected rather than the non-matches. |
... |
Additional arguments. |
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
.
Object of the same class as x
with the selected elements only.
Other subsetters:
brackets
,
keep_pos()
,
keep_re()
,
keep_types()
# For a 'freqlist' object--------------------- (flist <- freqlist("The man and the mouse.", as_text = TRUE)) keep_bool(flist, type_freqs(flist) < 2) drop_bool(flist, type_freqs(flist) >= 2) keep_bool(flist, ranks(flist) <= 3) keep_bool(flist, c(FALSE, TRUE, TRUE, FALSE)) (flist2 <- keep_bool(flist, type_freqs(flist) < 2)) keep_bool(flist2, orig_ranks(flist2) > 2) # For a 'types' object ---------------------- (tps <- as_types(letters[1:10])) keep_bool(tps, c(TRUE, FALSE)) drop_bool(tps, c(TRUE, FALSE)) # For a 'tokens' object ---------------------- (tks <- as_tokens(letters[1:10])) keep_bool(tks, c(TRUE, FALSE)) drop_bool(tks, c(TRUE, FALSE))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.