R语言 把一个对象转换成一个字符串–toString()函数
R语言中的 toString() 函数用于将一个对象转换为一个单字符字符串。
语法: toString(x, width)
参数:
x: 对象
width: 最大字符串宽度
例子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)
输出
[1] "Geeks, for, geeks"
[1] "Geeks, f...."
例2 :
# R program to convert an object to string
# Creating a matrix
x <- matrix(c(1:9), 3, 3)
# Calling toString() Function
toString(x)
输出
[1] "1, 2, 3, 4, 5, 6, 7, 8, 9"