toString() function in R Programming 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
R
# R program to illustrate # toString function # Initializing a string vector x <- c("GFG", "Geeks", "GeeksforGeekss") # Calling the toString() function toString(x)
Output :
[1] "GFG, Geeks, GeeksforGeekss"
# 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)
Output:
[1] "GF...." [1] "GFG, ...." [1] "GFG, G...."
# Matrix having 3 rows and 3 columns # filled by a single constant 5 mat <- (matrix(5, 3, 3)) print(mat) str <- toString(mat) print("String") print(str)
Output:
[,1] [,2] [,3] [1,] 5 5 5 [2,] 5 5 5 [3,] 5 5 5 [1] "String" [1] "5, 5, 5, 5, 5, 5, 5, 5, 5"
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.