In this tutorial you will learn about the R String toString and its application with practical example.
R String toString
The toString() function is used to convert an R Object to a Character String. It is a helper function used with format, to produce a single character string describing an R object.
Syntax:-
1 2 3 4 |
toString(x, ...) ## Default S3 method: toString(x, width = NULL, ...) |
Above is the general syntax of toString() function, it first converts x to character type and then concatenates the elements with “, “. If width is passed and it is not a NULL value, then it returns the first width – 4 characters of the result appended with (….), in case of full result using more than width specified.
x:- It is a R object to be converted.
width:- It represents the maximum field width. The minimum value for width can be 6 and anything smaller than 6 is taken as 6, 0 or NULL indicate no maximum.
… :- It is the optional arguments passed to or from methods.
Example:-
1 2 3 4 |
print("W3Adda - R toString function.") x <- c("a", "b", "aaaaaaaaaaa") toString(x) toString(x, width = 8) |
Output:-