matrix(c(1,2,3,4,5)...">

Is there a name for this "repeating" vector behavior in R?

I noticed that many R hackers are doing something like this:

> matrix(c(1,2,3,4,5),nrow=5,ncol=10,byrow=FALSE)
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    1    1    1    1    1    1    1    1    1     1
[2,]    2    2    2    2    2    2    2    2    2     2
[3,]    3    3    3    3    3    3    3    3    3     3
[4,]    4    4    4    4    4    4    4    4    4     4
[5,]    5    5    5    5    5    5    5    5    5     5

In principle, if the size of the vector (in this case 5) is shorter than the size of the "container" in which it is placed, in this case the matrix (5 x 10 = 50 in size), it will be repeated until it fills the container. I think this is an absolutely neat feature of R that makes many R codes very concise. Is there a name for this? and documentation about it?

I noticed this pattern from the following code snippet from ( http://training.bioinformatics.ucdavis.edu/docs/2012/05/DAV/lectures/gene-expression-analysis/gene-expression-analysis.pdf ). The function basically takes a data matrix and normalizes the quantiles

quan.norm<-function(x,quan=0.5){
  ##x: p by n data matrix, where columns are the samples.
  norm<-x
  p<-nrow(x)
  n<-ncol(x)
  x.sort<-apply(x, 2, sort) ## sort genes within a sample
  x.rank<-apply(x,2,rank) ## rank genes within a sample
  ## find the common distribution to be matched to:
  qant.sort<-matrix(apply(x.sort,1,quantile, probs=quan),
                    + p,n,byrow=FALSE) #***<----- HERE ***

  ## match each sample to the common distribution:
  for (i in 1:n){
    norm[,i]<-qant.sort[x.rank[,i],i]
  }
  return(norm)
}

* , , .

+3
1

, .

From R Intro:

, , . , , , . , (, ), . , .

R manual

+1

All Articles