Brilliant, thanks!
-- TMK --
212-460-5430home
917-656-5351cell
>From: "James W. MacDonald" <[EMAIL PROTECTED]>
>To: Talbot Katz <[EMAIL PROTECTED]>
>CC: r-help@stat.math.ethz.ch
>Subject: Re: [R] Efficient way to repeat rows (or columns) of a matrix
Hi Talbot,
ma <- matrix(1:6, nrow = 2)
rma <- ma[rep(1:2, c(2,3)),]
Best,
Jim
Talbot Katz wrote:
> Hi.
>
> If I have a vector, v_1, and another vector of positive integers, i_1, the
> same length as v_1, then rep(v_1,i_1) will repeat v_i[j] exactly i_1[j]
> times, like so:
>
>
>>rep(c(1
Hi.
If I have a vector, v_1, and another vector of positive integers, i_1, the
same length as v_1, then rep(v_1,i_1) will repeat v_i[j] exactly i_1[j]
times, like so:
>rep(c(1,2,3),c(3,2,1))
[1] 1 1 1 2 2 3
>
I'd like to do the same sort of thing where I replace v_1 with a matrix, and
the jth