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 table or named numeric vector that will be interpreted as such.

tot_n_tokens

Number representing the total number of tokens in the corpus from which the frequency list is derived. When tot_n_tokens is NULL, this total number of tokens will be taken to be the sum of the frequencies in x.

sort_by_ranks

Logical. If TRUE, the items in the frequency list are sorted by frequency rank. If FALSE, the items in the frequency list, depending on the input type, either are sorted alphabetically or are not sorted at all.

Value

An object of class freqlist, which is based on the class table. It has additional attributes and methods such as:

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

freqlist()

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

[Package mclm version 0.2.7 Index]