String Manipulations—The stringr Package

Learn to clean and manipulate string data using stringr.

The stringr package is a valuable tool for manipulating text. It provides a wide range of functions for pattern matching, string splitting, string padding, and string substitution, among other tasks. For data scientists, the stringr package covers most needs for cleaning, preparing, and organizing text-based data—especially cleaning and extracting specific elements. Whether working with text data in a tidy dataset or dealing with messy strings in raw text files, stringr can help quickly clean and manipulate the data.

It’s worth noting that stringr essentially wraps another more specialized package called stringi. However, stringr tends to be easier to use and leverage than stringi because it’s highly condensed. But if you have a very specific string manipulation need that stringr can’t meet, it’s worth checking if stringi can meet that need instead.

Get hands-on with 1200+ tech skills courses.