将数字粘贴到数字

paste numeric to numeric

我只需要合并(如辫子?)包含数值的元素。我知道我可以 past(),但我需要将数字保持为数字。

x <- 1:2; x
# [1] 1 2
y <- c(9999, 9999); y
# [1] 9999 9999    
z <- [some function]; z
# [1] 1 9999 2 9999          # my desired output
class(z)
[1] "numeric"

我们可以使用Map,

unlist(Map(c, x, y))
#[1]    1 9999    2 9999

str(unlist(Map(c, x, y)))
# num [1:4] 1 9999 2 9999
class(unlist(Map(c, x, y)))
#[1] "numeric"

这里是 matrix() 的解决方案:

c(matrix(c(x,y), ,2, byrow=TRUE))