rep: Replicate Elements of Vectors and Lists - RDocumentation
文章推薦指數: 80 %
rep replicates the values in x . It is a generic function, and the (internal) default method is described here. rep.int and rep_len are faster simplified ... base(version3.6.2)Descriptionrepreplicatesthevaluesinx.Itisageneric function,andthe(internal)defaultmethodisdescribedhere. rep.intandrep_lenarefastersimplifiedversionsfor twocommoncases.Internally,theyaregeneric,somethodscanbe definedforthem.Usagerep(x,…)rep.int(x,times)rep_len(x,length.out)Argumentsxavector(ofanymodeincludingalist)orafactoror(for reponly)aPOSIXctorPOSIXltorDate object;oranS4objectcontainingsuchanobject.…furtherargumentstobepassedtoorfromothermethods. Fortheinternaldefaultmethodthesecaninclude: timesaninteger-valuedvectorgivingthe (non-negative)numberoftimestorepeateachelementifof lengthlength(x),ortorepeatthewholevectorifof length1.NegativeorNAvaluesareanerror.A doublevectorisaccepted,otherinputsbeingcoercedto anintegerordoublevector. length.outnon-negativeinteger.Thedesiredlengthofthe outputvector.Otherinputswillbecoercedtoadouble vectorandthefirstelementtaken.IgnoredifNAorinvalid. eachnon-negativeinteger.Eachelementofx isrepeatedeachtimes.Otherinputswillbecoercedto anintegerordoublevectorandthefirstelementtaken.Treatedas 1ifNAorinvalid. times,length.outsee…above.ValueAnobjectofthesametypeasx. rep.intandrep_lenreturnnoattributes(exceptthe classifreturningafactor). Thedefaultmethodofrepgivestheresultnames(whichwill almostalwayscontainduplicates)ifxhadnames,butretains nootherattributes.DetailsThedefaultbehaviourisasifthecallwasrep(x,times=1,length.out=NA,each=1) .Normallyjustoneoftheadditional argumentsisspecified,butifeachisspecifiedwitheither oftheothertwo,itsreplicationisperformedfirst,andthenthat impliedbytimesorlength.out. Iftimesconsistsofasingleinteger,theresultconsistsof thewholeinputrepeatedthismanytimes.Iftimesisa vectorofthesamelengthasx(afterreplicationby each),theresultconsistsofx[1]repeated times[1]times,x[2]repeatedtimes[2]timesand soon. length.outmaybegiveninplaceoftimes, inwhichcasexisrepeatedasmanytimesasis necessarytocreateavectorofthislength.Ifbotharegiven, length.outtakespriorityandtimesisignored. Non-integervaluesoftimeswillbetruncatedtowardszero. Iftimesisacomputedquantityitisprudenttoaddasmall fuzzoruseround.Andanalogouslyforeach. Ifxhaslengthzeroandlength.outissuppliedandis positive,thevaluesarefilledinusingtheextractionrules,thatis byanNAoftheappropriateclassforanatomicvector (0forrawvectors)andNULLforalist.ReferencesBecker,R.A.,Chambers,J.M.andWilks,A.R.(1988) TheNewSLanguage. Wadsworth&Brooks/Cole.SeeAlsoseq,sequence,replicate.ExamplesRunthiscode#NOTRUN{ rep(1:4,2) rep(1:4,each=2)#notthesame. rep(1:4,c(2,2,2,2))#sameassecond. rep(1:4,c(2,1,2,1)) rep(1:4,each=2,len=4)#first4only. rep(1:4,each=2,len=10)#8integersplustworecycled1's. rep(1:4,each=2,times=3)#length24,3completereplications rep(1,40*(1-.8))#length7onmostplatforms rep(1,40*(1-.8)+1e-7)#better ##replicatealist fred
延伸文章資訊
- 1R语言:rep函数解析_满腹的小不甘 - CSDN博客
R语言:rep函数解析 · x:代表的是你要进行复制的对象,可以是一个向量或者是一个因子。 · times:代表的是复制的次数,只能为正数。负数以及NA值都会为错误 ...
- 2How to Use rep() Function in R - R-Lang
The rep() is a built-in generic R function that replicates the values in the provided vector. The...
- 3R rep Function Examples - EndMemo
R rep Function ... rep(x) function replicates the values x. ... x : numeric vector, factor, list ...
- 4R語言rep()用法及代碼示例- 純淨天空
借助 rep() 方法,我們可以在R 編程中複製向量的元素。 用法: rep(x, times) 返回:Returns the replicated vectors. 範例1:. # Using...
- 5rep Function in R (3 Examples) - Statistics Globe
Definition: The rep R function replicates elements of vectors and lists. Basic R Syntax: You can ...