rep(base)
rep()所属R语言包:base
Replicate Elements of Vectors and Lists
复制的向量和列表元素
译者:生物统计家园网 机器人LoveR
描述----------Description----------
rep replicates the values in x. It is a generic function, and the (internal) default method is described here.
repx复制的值。它是一个通用的功能,这里所描述的(内部)的默认方法。
rep.int is a faster simplified version for the most common case.
rep.int是最常见的情况更快的简化版本。
用法----------Usage----------
rep(x, ...)
rep.int(x, times)
参数----------Arguments----------
参数:x
a vector (of any mode including a list) or a pairlist or a factor or (except for rep.int) a POSIXct or POSIXlt or date object; or also, an S4 object containing a vector of the above kind.
矢量(包括列表中的任何模式)或1 pairlist或(除rep.int)POSIXct或POSIXlt或date对象的一个因素;也中S4中对象包含上述类型的向量。
参数:...
further arguments to be passed to or from other methods. For the internal default method these can include:
进一步的参数被传递到或从其他方法。这些对于内部默认的方法可以包括:
timesA integer 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.
times给予(非负)次重复每一个元素,如果长length(x),或重复,如果整向量的长度为1的一个整数向量。负或NA值是一个错误。
length.outnon-negative integer. The desired length of the output vector. Other inputs will be coerced to an integer vector and the first element taken. Ignored if NA or invalid.
length.out非负整数。所需的输出向量的长度。其他输入将被裹挟到一个整数向量和采取的第一个元素。忽视如果NA或无效的。
eachnon-negative integer. Each element of x is repeated each times. Other inputs will be coerced to an integer vector and the first element taken. Treated as 1 if NA or invalid.
each非负整数。 x的每个元素重复each倍。其他输入将被裹挟到一个整数向量和采取的第一个元素。视为1如果NA或无效。
参数:times
see ....
看到...。
Details
详情----------Details----------
The default behaviour is as if the call was rep(x, times=1, length.out=NA, each=1). 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.
默认行为是,如果调用了rep(x, times=1, length.out=NA, each=1)。通常只是一个额外的参数指定,但如果each与其他两个或者指定的,其复制被首先执行,然后times或length.out暗示。
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如果x(each复制)后相同长度的向量,结果由x[1]重复times[1]次<X >反复x[2]倍等。
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,在这种情况下,x是多次重复是必要的,以创建一个这个长度的向量。如果两者都给出length.out优先times被忽略。
Non-integer values of times will be truncated towards zero. If times is a computed quantity it is prudent to add a small fuzz.
times非整数值将被截断向零。 times如果是添加一个小绒毛,是审慎的计算量。
If x has length zero and length.out is supplied and is positive, the values are filled in using the extraction rules, that is by an NA of the appropriate class for an atomic vector (0 for raw vectors) and NULL for a list.
如果x长度为零的,length.out提供的,是积极的,充满在使用的提取规则,通过适当的原子向量类的NA(值 0为原料的向量)和NULL列表。
值----------Value----------
An object of the same type as x (except that rep will coerce pairlists to vector lists).
x(除,rep会强迫pairlists向量名单)同一类型的对象。
rep.int returns no attributes.
rep.int返回任何属性。
The default method of rep gives the result names (which will almost always contain duplicates) if x had names, but retains no other attributes except for factors.
默认的方法rep结果名称(这几乎总是包含重复)如果x有名字,但没有其他属性保留的因素除外。
注意----------Note----------
Function rep.int is a simple case handled by internal code, and provided as a separate function purely for S compatibility.
功能rep.int处理内部代码是一个简单的例子,作为一个单独的功能,并提供完全的兼容性。
Function rep is a primitive, but (partial) matching of argument names is performed as for normal functions. You can no longer pass a missing argument to e.g. length.out.
功能rep是一个原始的,但参数名(部分)匹配的正常功能。你再也不能缺少的参数传递例如length.out。
参考文献----------References----------
The New S Language. Wadsworth & Brooks/Cole.
参见----------See Also----------
seq, sequence, replicate.
seq,sequence,replicate。
举例----------Examples----------
rep(1:4, 2)
rep(1:4, each = 2) # not the same.[不一样的。]
rep(1:4, c(2,2,2,2)) # same as second.[作为第二个相同的。]
rep(1:4, c(2,1,2,1))
rep(1:4, each = 2, len = 4) # first 4 only.[第4只。]
rep(1:4, each = 2, len = 10) # 8 integers plus two recycled 1's.[8整数加两国回收1。]
rep(1:4, each = 2, times = 3) # length 24, 3 complete replications[长度为24,3个完整的复制]
rep(1, 40*(1-.8)) # length 7 on most platforms[在大多数平台上长7]
rep(1, 40*(1-.8)+1e-7) # better[更好]
## replicate a list[#复制列表]
fred <- list(happy = 1:10, name = "squash")
rep(fred, 5)
# date-time objects[日期时间对象]
x <- .leap.seconds[1:3]
rep(x, 2)
rep(as.POSIXlt(x), rep(2, 3))
## named factor[#名为因素]
x <- factor(LETTERS[1:4]); names(x) <- letters[1:4]
x
rep(x, 2)
rep(x, each=2)
rep.int(x, 2) # no names[没有名字]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|