载体 a
和 b
可以使用 toString(width = 10)
缩短在 Base R 中导致以 ....
结尾的较短向量
但是,我想知道如何使缩短的向量以 ..., last vector element
结尾?
我的 desired_output
如下所示。
a <- 1:26
b <- LETTERS
toString(a, width = 10)
# [1] "1,2,...."
desired_output1 = "1,2,...,26"
toString(b, width = 10)
# [1] "A,B,...."
desired_output2 = "A,B,...,Z"
最佳答案
你可以只添加结尾。
paste(toString(a, width = 10), a[length(a)], sep=", ")
[1] "1, 2, ...., 26"
paste(toString(b, width = 10), b[length(b)], sep=", ")
[1] "A, B, ...., Z"
https://stackoverflow.com/questions/70550869/