Trim a String to a Specified Display Width in R Programming – strtrim() Function
Last Updated :
12 Jun, 2020
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:
x1 < - "GeeksforGeeks"
x2 < - "R Programming"
strtrim(x1, 5 )
strtrim(x2, 7 )
|
Output:
[1] "Geeks"
[1] "R Progr"
Example 2:
x < - c( "Hello" , "Geeks" , "GFG" )
strtrim(x, 2 )
strtrim(x, c( 1 , 2 , 3 ))
|
Output:
[1] "He" "Ge" "GF"
[1] "H" "Ge" "GFG"
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...