term_before: Extract Terms from Relative Locations

Description Usage Arguments Value Examples

View source: R/term_before.R

Description

term_before - View the frequency of terms before a regex/term.

term_after - View the frequency of terms after a regex/term.

term_first - View the frequency of terms starting each string.

Usage

1
2
3
4
5
term_before(text.var, term, ignore.case = TRUE, ...)

term_after(text.var, term, ignore.case = TRUE, ...)

term_first(text.var, ignore.case = TRUE, ...)

Arguments

text.var

The text string variable.

term

A regex term to provide the search position.

ignore.case

logical. If FALSE, the pattern matching is case sensitive and if TRUE, case is ignored during matching.

...

ignored.

Value

Returns a data.frame of terms and frequencies

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
term_before(presidential_debates_2012$dialogue, 'president')
term_after(presidential_debates_2012$dialogue, 'president')
term_after(presidential_debates_2012$dialogue, 'oil')
term_first(presidential_debates_2012$dialogue)

x <- term_before(presidential_debates_2012$dialogue, 'president')
plot(x)

## Not run: 
library(dplyr); library(lexicon)

pos_df_pronouns[['pronoun']][1:5] %>%
    lapply(function(x){
        term_after(presidential_debates_2012$dialogue, paste0("\\b", x, "\\b"))
    }) %>%
    setNames(pos_df_pronouns[['pronoun']][1:5])

term_first(presidential_debates_2012$dialogue) %>%
    filter(!term %in% tolower(sw_dolch) & !grepl("'", term))

## End(Not run)

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