rep( )函数--R语言

函数功能

rep replicates the values in x. 

复制x中的值

函数语法:

rep(x, times = 1, length.out = NA, each = 1)

函数参数:

x
a vector (of any mode including a list) or a factor 
or (for rep only) a POSIXct or POSIXlt or Date object; 
or an S4 object containing such an object.

x: 重复的对象

times
an integer-valued vector giving the (non-negative) number of times 
to repeat each element if of length length(x), 
or to repeat the whole vector if of length 1. 
Negative or NA values are an error. 
A double vector is accepted, 
other inputs being coerced to an integer or double vector.

times: 重复次数
在这里插入图片描述

If ‘times’consists of a single integer, 
the result consists of the whole input repeated this many times. 
If ‘times’ is a vector of the same length as ‘x’ (after replication by each), 
the result consists of x[1] repeated times[1] times, 
x[2] repeated times[2] times and so on.

当参数times为单个整数,则将整个输入重复times次。若times是与复制对象x(each参数执行之后)长度相同的向量,则向量x中的每个元素对应重复times中对应位置数据的次数。
在这里插入图片描述

length.out
non-negative integer. 
The desired length of the output vector. 
Other inputs will be coerced to a double vector and the first element taken. 
Ignored if NA or invalid.

输出长度:非负数整数。当times或each与length.out同时指定时,必须满足length.out。
在这里插入图片描述

‘length.out’ may be given in place of ‘times’, 
in which case x is repeated as many times as is necessary to create a vector of this length. 
If both are given, length.out takes priority and times is ignored.

当创建某个长度的向量时,length.out会代替times参数出现。如果参数times与length.out同时给定,则length.out的设定优先满足。
在这里插入图片描述

each
non-negative integer. 
Each element of x is repeated each times.
Other inputs will be coerced to an integer or double vector 
and the first element taken. Treated as 1 if NA or invalid.

每个元素重复次数:非负整数型。
在这里插入图片描述

Normally just one of the additional arguments is specified, 
but if ‘each ’is specified with either of the other two, 
its replication is performed first, 
and then that implied by times or length.out.

通常只指定一个参数,但是如果each参数与某个参数一起指定,复制会首先执行,但需要满足times参数或length.out。
在这里插入图片描述
在这里插入图片描述

  • 5
    点赞
  • 51
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值