Description Usage Arguments Value Examples
View source: R/prep_tidy_text.R
Creates table with tokens for each class (if any).
1 | prep_tidy_text(x, target_col_name = NULL, text_col_name)
|
x |
x A data frame with one or more columns: the column with the classes
(if |
target_col_name |
A string with the column name of the target variable.
Defaults to |
text_col_name |
A string with the column name of the text variable. |
A data frame with two or three columns: classes (if target_col_name
is not NULL
); line numbers; and tokens.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #' library(experienceAnalysis)
books <- janeaustenr::austen_books() # Jane Austen books
emma <- paste(books[books$book == "Emma", ], collapse = " ") # String with whole book
pp <- paste(books[books$book == "Pride & Prejudice", ], collapse = " ") # String with whole book
# Make data frame with books Emma and Pride & Prejudice
x <- data.frame(
text = c(emma, pp),
book = c("Emma", "Pride & Prejudice")
)
# Tokens for both books, without the `target_col_name` column
prep_tidy_text(x, target_col_name = NULL, text_col_name = "text") %>%
head()
# Tokens for both books, with the `target_col_name` column this time
prep_tidy_text(x, target_col_name = "book", text_col_name = "text") %>%
split(.$book) %>%
purrr::map(~ head(.))
# Tokens for Pride & Prejudice
prep_tidy_text(x, target_col_name = "book", text_col_name = "text") %>%
dplyr::filter(book == "Pride & Prejudice") %>%
head()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.