gpt4 book ai didi

r - 如何从 2 个向量中创建一个对列表

转载 作者:行者123 更新时间:2023-12-04 12:20:05 26 4
gpt4 key购买 nike

说我有

X = seq(1,10,1)
X0 = c(-Inf,X)
X1 = c(X,Inf)

如何列出对(-Inf,1);(1,2);...;(10,+Inf)

这很接近但并不完全

R) test = mapply(c,c(-Inf,thresh),c(thresh,Inf))
R) test
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20]
[1,] -Inf 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95
[2,] 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 Inf

最佳答案

你快到了:

mapply(c, X0, X1, SIMPLIFY = FALSE)
# [[1]]
# [1] -Inf 1
#
# [[2]]
# [1] 1 2
# ...
# [[11]]
# [1] 10 Inf

关于r - 如何从 2 个向量中创建一个对列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24159624/

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