Extracts one text/textarea item's responses from a response data frame and applies light, configurable cleaning: lower-casing, punctuation removal, and optional number stripping. Blank and missing responses are dropped rather than kept as empty strings, since they carry no term-frequency signal and would otherwise inflate downstream response counts.
Usage
sframe_clean_text(
data,
item_id,
lowercase = TRUE,
remove_punct = TRUE,
strip_numbers = FALSE,
instrument = NULL
)Arguments
- data
A data.frame of responses.
- item_id
Character. The text/textarea item's column name.
- lowercase
Logical. Lower-case the text. Default
TRUE.- remove_punct
Logical. Strip punctuation. Default
TRUE.- strip_numbers
Logical. Strip digits. Default
FALSE.- instrument
Optional
sframeinstrument. When supplied,item_idis validated as a"text"or"textarea"item before cleaning.
Value
A character vector of cleaned responses, with an integer
"respondent" attribute giving each entry's original row index in
data, so quotes extracted later can cite a respondent.
See also
Other Text analysis functions:
sframe_extract_quotes(),
sframe_ngram_frequency(),
sframe_term_context(),
sframe_term_frequency()
Examples
demo <- sframe_demo("tourism_services")
cleaned <- sframe_clean_text(demo$responses, "comments")
head(cleaned)
attr(cleaned, "respondent")[1:5]