String Manipulation with stringr in R

Learn how to pull character strings apart, put them back together and use the stringr package.
Start Course for Free
4 Hours17 Videos60 Exercises21,557 Learners
5150 XP

Create Your Free Account

By continuing you accept the Terms of Use and Privacy Policy. You also accept that you are aware that your data will be stored outside of the EU and that you are above the age of 16.

Loved by learners at thousands of companies

Course Description

Character strings can turn up in all stages of a data science project. You might have to clean messy string input before analysis, extract data that is embedded in text or automatically turn numeric results into a sentence to include in a report. Perhaps the strings themselves are the data of interest, and you need to detect and match patterns within them. This course will help you master these tasks by teaching you how to pull strings apart, put them back together and use stringr to detect, extract, match and split strings using regular expressions, a powerful way to express patterns.

  1. 1

    String basics

    You'll start with some basics: how to enter strings in R, how to control how numbers are transformed to strings, and finally how to combine strings together to produce output that combines text and nicely formatted numbers.
    Play Chapter Now
  2. 2

    Introduction to stringr

    Time to meet stringr! You'll start by learning about some stringr functions that are very similar to some base R functions, then how to detect specific patterns in strings, how to split strings apart and how to find and replace parts of strings.
    Play Chapter Now
  3. 3

    Pattern matching with regular expressions

    In this chapter you'll learn about regular expressions, a language for describing patterns in strings. By combining regular expressions with the stringr functions you'll greatly increase your power to manipulate strings.
    Play Chapter Now
  4. 4

    More advanced matching and manipulation

    Now for two advanced ways to use regular expressions along with stringr: selecting parts of a match (a.k.a capturing) and referring back to parts of a match (a.k.a back-referencing). You'll also learn to deal with and strings or patterns that contain Unicode characters (e.g. é).
    Play Chapter Now
  5. 5

    Case studies

    Practice your string manipulation skills on a couple of case studies. You'll also learn a few new skills, reading strings into R and handling problems of case (e.g. A versus a).
    Play Chapter Now
In the following tracks
R ProgrammerText Mining
Tom JeonRichie Cotton
Intermediate R
Charlotte Wickham Headshot

Charlotte Wickham

Assistant Professor at Oregon State University
Charlotte is an Assistant Professor in the Department of Statistics at Oregon State University and an avid R programmer with a passion for teaching. Her interests lie in spatiotemporal data, statistical graphics and computing, and environmental statistics.
See More

What do other learners have to say?

I've used other sites—Coursera, Udacity, things like that—but DataCamp's been the one that I've stuck with.

Devon Edwards Joseph
Lloyds Banking Group

DataCamp is the top resource I recommend for learning data science.

Louis Maiden
Harvard Business School

DataCamp is by far my favorite website to learn from.

Ronald Bowers
Decision Science Analytics, USAA