Trim a String to a Specified Display Width in R Programming – strtrim() Function Last Updated : 12 Jun, 2020 Improve Improve Like Article Like Save Share 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: # 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: # 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" Like Article Suggest improvement Previous Printing out to the Screen or to a File in R Programming - cat() Function Next Get the Number of Levels of a Factor in R Programming - nlevels() Function Share your thoughts in the comments Add Your Comment Please Login to comment...