as_types {mclm} | R Documentation |
Coerce object to a vector of types
Description
This function coerces an object, such as a character vector, to an object of
class types
.
Usage
as_types(x, remove_duplicates = TRUE, sort = TRUE, ...)
Arguments
x |
Object to coerce |
remove_duplicates |
Logical. Should duplicates be removed from |
sort |
Logical. Should |
... |
Additional arguments (not implemented) |
Value
An object of the class types
, which is based on a character vector.
It has additional attributes and methods such as:
base
print()
,as_data_frame()
,sort()
andbase::summary()
(which returns the number of items and of unique items),subsetting methods such as
keep_types()
,keep_pos()
, etc. including[]
subsetting (see brackets).
An object of class types
can be merged with another by means of types_merge()
,
written to file with write_types()
and read from file with write_types()
.
See Also
Examples
toy_corpus <- "Once upon a time there was a tiny toy corpus.
It consisted of three sentences. And it lived happily ever after."
flist <- freqlist(toy_corpus, re_token_splitter = "\\W+", as_text = TRUE)
print(flist, n = 1000)
(sel_types <- as_types(c("happily", "lived", "once")))
keep_types(flist, sel_types)
tks <- tokenize(toy_corpus, re_token_splitter = "\\W+")
print(tks, n = 1000)
tks[3:12] # idx is relative to selection
head(tks) # idx is relative to selection
tail(tks) # idx is relative to selection