Open In App

Trim a String to a Specified Display Width in R Programming - strtrim() Function

Last Updated : 12 Jun, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
strtrim() function in R Language is used to trim a string to a specified display width.
Syntax: strtrim(x, width) Parameters: x: character vector width: specified width
Example 1: Python3 1==
# R program to trim a string
# to specified width

# Creating a vector
x1 <- "GeeksforGeeks"
x2 <- "R Programming"

# Calling strtrim() function
strtrim(x1, 5)
strtrim(x2, 7)
Output:
[1] "Geeks"
[1] "R Progr"
Example 2: Python3 1==
# R program to trim a string
# to specified width

# Creating a vector
x <- c("Hello", "Geeks", "GFG")

# Calling strtrim() function
strtrim(x, 2)
strtrim(x, c(1, 2, 3))
Output:
[1] "He" "Ge" "GF"
[1] "H"   "Ge"  "GFG"

Next Article

Similar Reads