sub_in_na: Regex Sub to Missing

Description Usage Arguments Value Examples

Description

Use a regex to identify elements to sub out for missing NA. Useful within a magrittr pipeline before producing the TermDocumentMatrix or DocumentTermMatrix.

Usage

1
sub_in_na(x, regex = "^[^A-Za-z]*$", ...)

Arguments

x

A vector of text strings.

regex

A regex to match strings in a vector.

...

Other arguments passed to grepl

Value

Returns a vector with NAs inserted.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
x <- c("45", "..", "", "   ", "dog")
sub_in_na(x)
sub_in_na(x, "^\\s*$")

## Not run: 
library(tidyverse)
x %>%
    q_dtm() %>%
    as.matrix()

x %>%
    sub_in_na() %>%
    q_dtm() %>%
    as.matrix()

## End(Not run)

trinker/gofastr documentation built on May 31, 2019, 8:43 p.m.