Write R code to create a variable sentence with the text "I love R programming". Convert the text to lowercase, replace "R" with "Python", and then split the sentence into individual words.
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.
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.