as_freqlist {mclm} | R Documentation |
Coerce table to a frequency list
Description
This function coerces an object of class table
to an object of class freqlist
.
Usage
as_freqlist(x, tot_n_tokens = NULL, sort_by_ranks = TRUE)
Arguments
x |
Object of class |
tot_n_tokens |
Number representing the total number of tokens in the
corpus from which the frequency list is derived. When |
sort_by_ranks |
Logical.
If |
Value
An object of class freqlist
, which is based on the class table
.
It has additional attributes and methods such as:
base
print()
,as_data_frame()
,summary()
andsort
,an interactive
explore()
method,various getters, including
tot_n_tokens()
,n_types()
,n_tokens()
, values that are also returned bysummary()
, and more,subsetting methods such as
keep_types()
,keep_pos()
, etc. including[]
subsetting (see brackets).
Additional manipulation functions include type_freqs()
to extract the frequencies
of different items, freqlist_merge()
to combine frequency lists, and
freqlist_diff()
to subtract a frequency list from another.
Objects of class freqlist
can be saved to file with write_freqlist()
;
these files can be read with read_freqlist()
.
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."
## make frequency list in a roundabout way
tokens <- tokenize(toy_corpus)
flist <- as_freqlist(table(tokens))
flist
## more direct procedure
freqlist(toy_corpus, as_text = TRUE)
## build frequency list from scratch: example 1
flist <- as_freqlist(c("a" = 12, "toy" = 53, "example" = 20))
flist
## build frequency list from scratch: example 2
flist <- as_freqlist(c("a" = 12, "toy" = 53, "example" = 20),
tot_n_tokens = 1300)
flist