mutate_counts: Apply Normalization to Term/Token Columns

Description Usage Arguments Value Examples

View source: R/mutate_counts.R

Description

Apply normalization to a term count columns of termco object without stripping the class & attributes of the object.

Usage

1
mutate_counts(x, fun = function(x) as.integer(x > 0))

Arguments

x

A term_count object.

fun

A function to apply column-wise.

...

ignored.

Value

Returns a term_count object.

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
40
41
42
43
## Not run: 
library(dplyr)

term_list <- list(
    `if` = c('if'),
    ands = c('an'),
    or = c('or'),
    buts = c('but')
)

out <- presidential_debates_2012 %>%
     with(term_count(dialogue, TRUE, term_list))

out

## default one-hot encoding
out %>%
    mutate_counts()

## min-max scaling
out %>%
    mutate_counts(function(x) (x - min(x)) / ((max(x) - min(x))))

## token counts
token_list <- list(
    person = c('sam', 'i'),
    place = c('here', 'house'),
    thing = c('boat', 'fox', 'rain', 'mouse', 'box', 'eggs', 'ham'),
    no_like = c('not like')
)

out2 <- token_count(sam_i_am, grouping.var = TRUE, token.list = token_list)

## default one-hot encoding
out2 %>%
    mutate_counts()

## min-max scaling
out2 %>%
    mutate_counts(function(x) (x - min(x)) / ((max(x) - min(x))))


## End(Not run)

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