The “trimws” Function in R
Package: Base R (No specific package, it’s a built-in function)
Purpose: To trim whitespace from the beginning and/or end of each string in a character vector.
General Class: String Manipulation
Required Argument(s):
x: A character vector from which to trim whitespace.
Notable Optional Arguments:
None
Example:
# Example usage
words <- c(" apple", "banana ", " orange ", "grape")
# Trim whitespace from both sides of each string
trimmed_words <- trimws(words)
print(trimmed_words)In this example, the trimws function from base R is used to trim whitespace from both sides of each string in the character vector words. The result is a character vector with trimmed strings.