r - 如何在 R 中的另一个向量元素中按次重复向量元素?
问题描述
我想重复每一个
repeat.it <- c(0, 3951982, 7635488, 10986941)
按次:
repeat.times<- c(2L, 3L, 4L, 2L)
并得到结果:
0,0,3951982,3951982,3951982,7635488,7635488,7635488,7635488,10986941,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
推荐阅读
- java - 为什么 Cmds.java 中的 getPlugin 方法不起作用?
- php - 在参数中传递用户作为依赖注入 - symfony4
- julia - 带有数据框的条件语句 [Julia v1.0]
- printing - 如何在 netsuite 中打印不同的模板?
- c - 如何使用 C 在 windows 中的创建进程函数中更改环境变量?
- tensorflow - 计算张量流中所有梯度的总和
- swift - 可解码强制超级开放类实现初始化器
- python - 安装后pip安装方法不起作用
- r - R Markdown没有显示其他引擎的执行按钮
- c++ - C++ 我的文件在我尝试将它们移动到源文件之前一直在工作,现在没有错误,也没有显示任何内容