“每个"的值不止一个“rep"中的参数功能? [英] More than one value for "each" argument in "rep" function?

查看:43
本文介绍了“每个"的值不止一个“rep"中的参数功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为 R 中的rep"函数中的每个"参数分配一个以上的值?一个简单的例子,其中向量中的每个值在一行中重复 3 次:

How to assign more than one value for "each" argument in "rep" function in R? A trivial example, where each value in a vector is 3-times repeated in a row:

a <- seq(2,6,2)
rep (a,each = 3)

但是,如果我在each"参数中添加多个值以更改每个值的重复次数,则无法正常工作:

However, if I add more than one value in "each" argument in order to change the number of repetition of each value, it doesn't work properly:

rep (a, each = c(2,4,7))

如何解决?先感谢您.

推荐答案

根据您认为输出应该是什么,我猜您需要 times= 参数:

Depending on what you think the output should be, I'm guessing you want the times= parameter:

rep (a, times = c(2, 4, 7))
# [1] 2 2 4 4 4 4 6 6 6 6 6 6 6

区别见?rep

这篇关于“每个"的值不止一个“rep"中的参数功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆