a <- matrix(1:8, 2, 4, byrow=TRUE)
b<-t(a)
r<-rep(b,5) # can insert anything for 5
matrix(r,ncol=dim(a)[2],byrow=T)
      [,1] [,2] [,3] [,4]
 [1,]    1    2    3    4
 [2,]    5    6    7    8
 [3,]    1    2    3    4
 [4,]    5    6    7    8
 [5,]    1    2    3    4
 [6,]    5    6    7    8
 [7,]    1    2    3    4
 [8,]    5    6    7    8
 [9,]    1    2    3    4
[10,]    5    6    7    8


Am 26.04.2012 um 13:38 schrieb Petr PIKAL:

> Hi
> 
> what about
> 
> rbind(a,a)
>     [,1] [,2] [,3] [,4]
> [1,]    1    2    3    4
> [2,]    5    6    7    8
> [3,]    1    2    3    4
> [4,]    5    6    7    8
> 
> Regards
> Petr
> 
> 
>> 
>>> a <- matrix(1:8, 2, 4, byrow=TRUE)
>>> a
>>     [,1] [,2] [,3] [,4]
>> [1,]    1    2    3    4
>> [2,]    5    6    7    8
>>> a[c(1,2,1,2),]
>>     [,1] [,2] [,3] [,4]
>> [1,]    1    2    3    4
>> [2,]    5    6    7    8
>> [3,]    1    2    3    4
>> [4,]    5    6    7    8
>>> 
>> 
>> On Wed, Apr 25, 2012 at 8:32 PM, Rebecca <rebecca0...@yahoo.cn> wrote:
>> 
>>> Hi,
>>> If I have a matrix like
>>> 1  2  3  4
>>> 5  6  7  8,
>>> how can I repeat two rows as whole, to be like
>>> 1  2  3  4
>>> 5  6  7  8
>>> 1  2  3  4
>>> 5  6  7  8?
>>> 
>>> Since I have more two rows in a matrix and I need to repeat many 
> times, I
>>> wonder whether there is a convenient command to do so.
>>> 
>>> Thanks!
>>>       [[alternative HTML version deleted]]
>>> 
>>> 
>>> ______________________________________________
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html<http://www.r-project.org/
>> posting-guide.html>
>>> and provide commented, minimal, self-contained, reproducible code.
>>> 
>>> 
>> 
>>   [[alternative HTML version deleted]]
>> 
>> ______________________________________________
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to