Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.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,我想重复每一次 repeat.it <- c(0, 3951982, 7635488, 10986941) 我试过的代码: rep(repeat.it,each=repeat.times)但这似乎给了我错误的结果。我怎样才能做好呢?差不多了: rep(repeat.it, times = repeat.times) # [1] 0 0 3951982 3951982 3951982 7635488 7635488 # [8] 7635488

我想重复每一次

repeat.it <- c(0, 3951982, 7635488, 10986941)
我试过的代码:
rep(repeat.it,each=repeat.times)
但这似乎给了我错误的结果。我怎样才能做好呢?

差不多了:

rep(repeat.it, times = repeat.times)
#  [1]        0        0  3951982  3951982  3951982  7635488  7635488
#  [8]  7635488  7635488 10986941 10986941
差不多了:

rep(repeat.it, times = repeat.times)
#  [1]        0        0  3951982  3951982  3951982  7635488  7635488
#  [8]  7635488  7635488 10986941 10986941
这是一个选择

res <- mapply(rep, repeat.it, repeat.times)
res <- unlist(res)
res这是一个选项

res <- mapply(rep, repeat.it, repeat.times)
res <- unlist(res)

res@MAPK,它回答了你的问题吗?@MAPK,它回答了你的问题吗?