Working with stringr
The stringr
package provides a cohesive set of functions that all start with str_
and are designed to make working with strings as easy as possible.
Let’s start with the basic functions of stringr
by replicating the same results from the previous exercise.
Basics of stringr
The str_c()
function from the stringr
package can concatenate multiple strings with similar functionalities as in paste()
. Let’s see its use in action.
Exercise 3.9 – combining strings using paste()
In this exercise, we will reproduce the same as what we did in Exercise 3.8 using str_c()
:
- Concatenate
statistics
withworkshop
with a separating space in between:>>> str_c("statistics", "workshop", sep = " ") "statistics workshop"
We can use the
sep
argument to specify the separator between strings. - Combine a vector of
statistics
andworkshop
withcourse
:>>> str_c(c("statistics", "...