Skip to content
Related Articles

Related Articles

Convert an Object to a String in R Programming – toString() Function
  • Last Updated : 17 Jun, 2020
GeeksforGeeks - Summer Carnival Banner

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

Syntax: toString(x, width)

Parameters:
x: Object
width: maximum string width

Example 1:




# R program to convert an object to string
  
# Creating a vector
x <- c("Geeks", "for", "geeks"
  
# Calling toString() Function
toString(x)
toString(x, width = 12)

Output:



[1] "Geeks, for, geeks"
[1] "Geeks, f...."

Example 2:




# R program to convert an object to string
  
# Creating a matrix
x <- matrix(c(1:9), 3, 3)
  
# Calling toString() Function
toString(x)

Output:

[1] "1, 2, 3, 4, 5, 6, 7, 8, 9"

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :