In This Chapter
Representing textual data with character vectors
Working with text
Creating, converting, and working with factors
It’s not for no reason that reading and writing are considered to be two of the three Rs in elementary education (reading, ’riting, and ’rithmetic). In this chapter, you get to work with words in R.
You assign text to variables. You manipulate these variables in many different ways, including finding text within text and concatenating different pieces of text into a single vector. You also use R functions to sort text and to find words in text with some powerful pattern search functions, called regular expressions. Finally, you work with factors, the R way of representing categories (or categorical data, as statisticians call it).
Text in R is represented by character vectors. A character vector is — you guessed it! — a vector consisting of strings of characters. In Figure 5-1, you can see that each element of a character vector is a bit of text.