© Thomas Mailund 2019
Thomas MailundR Data Science Quick Referencehttps://doi.org/10.1007/978-1-4842-4894-2_8

8. Working with Strings: stringr

Thomas Mailund1 
Aarhus, Denmark
The stringr package gives you functions for string manipulation. The package will be loaded when you load the tidyverse package :
You can also load the package alone using

Counting String Patterns

The str_count() function counts how many tokens a string contain, where tokens, for example, can be characters or words.

By default, str_count() will count the number of characters in a string.
strings <- c(
    "Give me an ice cream",
    "Get yourself an ice cream",
    "We are all out of ice creams",
    "I scream, you scream, everybody loves ice cream.", ...

Get R Data Science Quick Reference: A Pocket Guide to APIs, Libraries, and Packages now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.