[R] rbind question

John Zhang jzhang at jimmy.harvard.edu
Tue Jul 8 16:11:09 CEST 2003

How about 

foo <- c(1,2,3)
bar <- matrix(rep(foo, 5), ncol = length(foo), byrow = TRUE)

>Date: 8 Jul 2003 15:58:25 +0200
>From: "David Andel" <andel at ifi.unizh.ch>
>To: r-help at stat.math.ethz.ch
>MIME-Version: 1.0
>Content-Transfer-Encoding: 8bit
>X-Virus-Scanned: by amavisd-milter (http://amavis.org/)
>X-Virus-Scanned: by amavisd-milter (http://amavis.org/)
>X-Spam-Status: No, hits=-5.3 required=5.0 tests=BAYES_01, HAS_ORGANIZATION 
>X-Spam-Checker-Version: SpamAssassin 2.54 (
>Subject: [R] rbind question
>X-BeenThere: r-help at stat.math.ethz.ch
>X-Mailman-Version: 2.1.2
>List-Id: Main R Mailing List: Primary help  <r-help.stat.math.ethz.ch>
>List-Help: <mailto:r-help-request at stat.math.ethz.ch?subject=help>
>List-Post: <mailto:r-help at stat.math.ethz.ch>
>List-Subscribe: <https://www.stat.math.ethz.ch/mailman/listinfo/r-help>, 
<mailto:r-help-request at stat.math.ethz.ch?subject=subscribe>
>List-Archive: <https://www.stat.math.ethz.ch/pipermail/r-help>
>List-Unsubscribe: <https://www.stat.math.ethz.ch/mailman/listinfo/r-help>, 
<mailto:r-help-request at stat.math.ethz.ch?subject=unsubscribe>
>I am trying to replicate a vector in n rows for comparison purposes with 
>another matrix.
>foo <- c(1,2,3)
>bar <- rbind(foo,foo) # does the trick for 2 rows
>bar <- rbind(rep(foo,2)) # does something else
>How do I generate a matrix with all rows=foo without writing 'foo' n times as 
>R-help at stat.math.ethz.ch mailing list

Jianhua Zhang
Department of Biostatistics
Dana-Farber Cancer Institute
44 Binney Street
Boston, MA 02115-6084

More information about the R-help mailing list