Searches through a set of text for a particular term and displays a table showing the cases that contain that search term. This is useful when trying to understand the context of a particular word or phrase in your text. The input text can be a Text variable, a character vector in an R Output, or the processed text from an item created by Text Analysis - Setup Text Analysis. If you use processed text to do the search, the table will display both the original text input and the processed text.
This blog post contains an example of searching text from tweets.
Examples
In Displayr, see How to Search for Terms in Text Analysis.
In Q:
- Go to Create > Text Analysis > Advanced > Search.
- Under Inputs > Input select a Text Analysis - Advanced - Setup Text Analysis object, a Text variable, or a character vector in an R Output.
- Enter a Search Term (in the example below, diet).
- Ensure the Automatic box is checked, or click Calculate
In this example, we have first processed the text from a survey question that asked people what they think is the difference between people who drink different types of cola, using Text Analysis - Setup Text Analysis. This is the initial step to some of the other text analysis options, and we used this as the input to our search. As the text has been pre-processed, the table shows both the original text and the results of the processing. If you use a text variable or character vector under Inputs > Input, then the result will instead be a single column containing the text only. The search term that has been used is the word diet, and it appears in bold when it is identified in the processed text.
Extract Sorted text
To get an output that contains only the processed text (i.e., only responses that contain the search term), take these steps:
1. Insert a new R Output (Displayr: Calculation > Custom Code from the toolbar; Q: Create > R Output).
2. In the R Code editor (in Q) or Code panel (in Displayr), use the code below, where text.search is the name of your Text Search output:
text.search$Processed.Text
3. Ensure the Automatic box (in Q) or Calculate automatically (in Displayr) is checked, or click Calculate.
Options
- Input The text that you want to search. This could be a Text variable, an R Output which is a "character" vector, or an item created by Text Analysis - Setup Text Analysis.
- Search Term The string that you want to search for.
See Also
Text Analysis - Setup Text Analysis
Displayr: How to Search for Terms in Text Analysis