Next →

Output:


      

Plots:

String Manipulation with stringr

The stringr package provides a consistent set of functions to work with text data in R. You can easily manipulate, detect, and format strings. Again, we cannot currently use the stringr library in our online environment, but the code snippets below show how this would work.

Common Operations

library(stringr)

# Sample string
text <- "R is great for data analysis"

# Convert to uppercase
str_to_upper(text)

# Detect if a word exists
str_detect(text, "data")

# Replace a word
str_replace(text, "data", "statistics")

# Split the string into words
str_split(text, " ")

These functions help clean, modify, and analyze text data efficiently.