[R] rbind question
Göran Broström
gb at stat.umu.se
Tue Jul 8 16:15:14 CEST 2003
On 8 Jul 2003, David Andel wrote:
> Hi
>
> 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
> arg?
Like this?
> foo <- c(1,2,3)
> n <- 5
> bar <- matrix(foo, nrow = n, ncol = length(foo), byrow = TRUE)
> bar
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 1 2 3
[3,] 1 2 3
[4,] 1 2 3
[5,] 1 2 3
G.
>
> Thanks,
> David
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
--
---
Göran Broström tel: +46 90 786 5223
Department of Statistics fax: +46 90 786 6614
Umeå University http://www.stat.umu.se/egna/gb/
SE-90187 Umeå, Sweden e-mail: gb at stat.umu.se
More information about the R-help
mailing list