如何从2个向量中列出对

时间:2014-06-11 09:43:20

标签: r list vector

说我有

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

1 个答案:

答案 0 :(得分:9)

你快到了:

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