[R] Help with use of rep function in R
Rolf Turner
r.turner at auckland.ac.nz
Tue Sep 8 04:38:10 CEST 2009
On 8/09/2009, at 2:20 PM, Subodh Acharya wrote:
> Dear List,I am trying to use rep function in the following conditions
> A = c( 5, 6, 7, 11, 9, 12, 10, 15)
> B = c(12,15, 21, 31, 25, 27,32, *34*,13,12, 34, 33, 24, 29, 26,
> *28*,22,14,27,22,21,12,32,
> 16)
>
> I need to repeat each element of A, as many times as each element
> of B, for
> the entire length of B.
> for example,
> repeat 5, for 12 times, 6 for 15 times,........, 15 for 34 times,
> and then,
> again, 5 for 13 times, 6 for 12 times,........, 15 for 28 times,
> and so on.
>
> I used, the function
> rep(A, times = B)
> It didn't work because apparently, the times command , worked for
> only if
> the length of A and B was equal.
A <- c( 5, 6, 7, 11, 9, 12, 10, 15)
B <- c(12,15, 21, 31, 25, 27,32, 34,13,12, 34, 33, 24, 29, 26,
28,22,14,27,22,21,12,32,16)
AA <- rep(A,length.out=length(B))
RA <- rep(AA,times=B)
cheers,
Rolf Turner
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
More information about the R-help
mailing list