Convert elements of a Vector to Strings in R Language – toString() Function

toString() function in R Language is used to produce a single character string describing an R object.

Syntax: toString(x, width = NULL)

Parameters:
x: R object
width: Suggestion for the maximum field width. Values of NULL or 0 indicate no maximum. The minimum value accepted is 6 and smaller values are taken as 6

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# toString function
  
# Initializing a string vector
x <- c("GFG", "Geeks", "GeeksforGeekss")
  
# Calling the toString() function
toString(x)

chevron_right


Output :

[1] "GFG, Geeks, GeeksforGeekss"

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# toString function
  
# Initializing a string vector
x <- c("GFG", "Geeks", "GeeksforGeekss")
  
# Calling the toString() function
toString(x, width = 2)
toString(x, width = 8)
toString(x, width = 10)

chevron_right


Output:

[1] "GF...."
[1] "GFG, ...."
[1] "GFG, G...."
My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.