Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在R中以规则间隔在向量中插入元素_R - Fatal编程技术网

如何在R中以规则间隔在向量中插入元素

如何在R中以规则间隔在向量中插入元素,r,R,对于此处解释的问题,是否有R的替代方法: 也就是说,从一个向量x可以生成一个矩阵并将其强制为一个向量 interval.length <- 4 as.vector(t(cbind(0, matrix(x, interval.length, byrow=T)))) # [1] 0 1 2 3 0 4 5 6 0 7 8 9 0 10 11 12 interval.length另一种方法是利用算术索引: y x <- 1:16 interval

对于此处解释的问题,是否有R的替代方法:


也就是说,从一个向量
x可以生成一个矩阵并将其强制为一个向量

interval.length <- 4
as.vector(t(cbind(0, matrix(x, interval.length, byrow=T))))
# [1]  0  1  2  3  0  4  5  6  0  7  8  9  0 10 11 12

interval.length另一种方法是利用算术索引:

y
    x <- 1:16
    interval.length <- 2
    co_interval.length <- length(x)/interval.length
    as.vector(t(cbind(0, matrix(x, co_interval.length, byrow=T))))

[1]  0  1  2  0  3  4  0  5  6  0  7  8  0  9 10  0 11 12  0 13 14  0 15 16
interval.length <- 4
as.vector(t(cbind(0, matrix(x, interval.length, byrow=T))))
# [1]  0  1  2  3  0  4  5  6  0  7  8  9  0 10 11 12