Introducing stringr

String Manipulation with stringr in R

Charlotte Wickham

Assistant Professor at Oregon State University

stringr

  • Powerful but easy to learn
  • Built on stringi
  • Concise and consistent
  • All functions start with str_
  • All functions take a vector of strings as the first argument
String Manipulation with stringr in R

str_c()

my_toppings
"green peppers" "olives"        "onions"
paste(c("", "", "and "), my_toppings, sep = "")
"green peppers" "olives"        "and onions"
library(stringr)
str_c(c("", "", "and "), my_toppings)
"green peppers" "olives"        "and onions"
  • str_length(), str_sub()
String Manipulation with stringr in R

Babynames

  • USA from 1880 to 2014
  • You'll use 2014 only
library(babynames)
head(babynames)
  year sex      name    n       prop
1 1880   F      Mary 7065 0.07238359
2 1880   F      Anna 2604 0.02667896
3 1880   F      Emma 2003 0.02052149
4 1880   F Elizabeth 1939 0.01986579
5 1880   F    Minnie 1746 0.01788843
6 1880   F  Margaret 1578 0.01616720
String Manipulation with stringr in R

Let's practice!

String Manipulation with stringr in R

Preparing Video For Download...