The “str_c” Function in R
Package: stringr
Purpose: To concatenate multiple strings into a single string.
General Class: String Manipulation
Required Argument(s):
...: Character vectors to be concatenated.
Notable Optional Arguments:
sep: Separator to be used between concatenated elements.
collapse: String to be used to collapse the elements into a single string.
Example:
# Example usage
library(stringr)
fruits <- c("apple", "banana", "orange", "grape")
# Concatenate fruits with a comma and space separator
concatenated_fruits <- str_c(fruits, collapse = ", ")
print(concatenated_fruits)In this example, the str_c function from the stringr package is used to concatenate the character vector fruits into a single string with a comma separator. The result is a character vector containing the concatenated string.