Reader small image

You're reading from  The Statistics and Machine Learning with R Workshop

Product typeBook
Published inOct 2023
Reading LevelIntermediate
PublisherPackt
ISBN-139781803240305
Edition1st Edition
Languages
Right arrow
Author (1)
Liu Peng
Liu Peng
author image
Liu Peng

Peng Liu is an Assistant Professor of Quantitative Finance (Practice) at Singapore Management University and an adjunct researcher at the National University of Singapore. He holds a Ph.D. in statistics from the National University of Singapore and has ten years of working experience as a data scientist across the banking, technology, and hospitality industries.
Read more about Liu Peng

Right arrow

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():

  1. Concatenate statistics with workshop 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.

  2. Combine a vector of statistics and workshop with course:
    >>> str_c(c("statistics", "...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
The Statistics and Machine Learning with R Workshop
Published in: Oct 2023Publisher: PacktISBN-13: 9781803240305

Author (1)

author image
Liu Peng

Peng Liu is an Assistant Professor of Quantitative Finance (Practice) at Singapore Management University and an adjunct researcher at the National University of Singapore. He holds a Ph.D. in statistics from the National University of Singapore and has ten years of working experience as a data scientist across the banking, technology, and hospitality industries.
Read more about Liu Peng