Strings

Although not all of us are linguists or text analysts, R functions for operating with text strings are still useful. They will come in handy when you need to match records in the data or select a portion of a textual record (for example, only the first name and not the surname). This section covers the basics of these operations.

Introduction

This chapter introduces you to string manipulation in R. You'll learn the basics of how strings work and how to create them by hand, but the focus of this chapter will be on regular expressions or regexps for short. Regular expressions are useful because strings usually contain unstructured or semi-structured data, and regexps are a concise language for describing patterns in strings. When you first look at a regexp, you'll think a cat walked across your keyboard, but as your understanding improves, they will soon start to make sense.


Prerequisites

This chapter will focus on the stringr package for string manipulation, which is part of the core tidyverse.

 library(tidyverse)


Source: H. Wickham and G. Grolemund, https://r4ds.had.co.nz/strings.html
Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 3.0 License.