gpt4 book ai didi

r - 缩短 R 中的长向量

转载 作者:行者123 更新时间:2023-12-05 08:24:52 29 4
gpt4 key购买 nike

载体 ab可以使用 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"

关于r - 缩短 R 中的长向量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70550869/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com