Skip to content
Related Articles

Related Articles

Convert elements of a Vector to Strings in R Language – toString() Function
  • Last Updated : 01 Jun, 2020

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 Articles
Page :