tidy_counts: Convert 'term_count' & 'token_count' to Tidy Form

Description Usage Arguments Value Note Examples

View source: R/tidy_counts.R

Description

Converts a wide matrix of counts to tidy form (tags are stretched long-wise with corresponding counts of tags).

Usage

1

Arguments

x

A 'term_count' object.

...

ignored.

Value

Returns a tibble with tags and counts in long form (retains all other variables in the 'term_count' object.

Note

n.words or n.tokens will be repeated for each row element id (element_id) and thus are nested.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
## On term counts
discoure_markers <- list(
    AA__response_cries = c("\\boh", "\\bah", "\\baha", "\\bouch", "yuk"),
    AA__back_channels = c("uh[- ]huh", "uhuh", "yeah"),
    BB__summons = "\\bhey",
    CC__justification = "because"
)

terms1 <- with(presidential_debates_2012,
    term_count(dialogue, TRUE, discoure_markers)
)

tidy_counts(terms1)


terms2 <- with(presidential_debates_2012,
    term_count(dialogue, list(person, time), discoure_markers)
)

tidy_counts(terms2)


## On token count
library(dplyr)
token_list <- lexicon::nrc_emotions %>%
    textshape::column_to_rownames() %>%
    t() %>%
    textshape::as_list()

token1 <- presidential_debates_2012 %>%
     with(token_count(dialogue, TRUE, token_list))

tidy_counts(token1)


token2 <- presidential_debates_2012 %>%
     with(token_count(dialogue, list(person, time), token_list))

tidy_counts(token2)

trinker/termco documentation built on Jan. 7, 2022, 3:32 a.m.