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 a in item created by How to Setup Text for Analysis. If you use processed text to do the search, the table will display both the original text input as well as the processed text.
This blog post contains an example of searching text from tweets.
A text variable
- Select Advanced Analysis > 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 below example, 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 How to Setup Text for 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: Insert > R Output; Q: Create > R Output).
2. In the R CODE field, use the code below, where text.search is the name of your Text Search output:
3. Ensure the Automatic box is checked, or click Calculate
- 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 How to Setup Text for Analysis.
- Search Term The string that you want to search for.