Re: [R] Putting the same array into a matrix

2010-10-14 Thread Charles C. Berry

On Thu, 14 Oct 2010, Desmond Lim wrote:


Hi,

I have an array and I want to put in into a matrix x number of times. Currently 
I doing this

matrix <- cbind(array, array, array).

Is there a more elegant way of doing this?


Fortunately!

If 'array' really is a matrix (bad choice of names here, Bub!), then

a.matrix <- matrix( rep( array, 3 ), nc = ncol( array )* 3 )

But this will work too:

a.matrix <- do.call( cbind, rep( list( array ), 3) )

even if 'array' is a data.frame

HTH,

Chuck




I've tried

matrix <- cbind(rep(array, times=x)) and matrix <- rep(cbind(array), times = 5)

but it didn't work.

Thanks.
__
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.



Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

__
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] Putting the same array into a matrix

2010-10-14 Thread Desmond Lim
Hi,

I have an array and I want to put in into a matrix x number of times. Currently 
I doing this

matrix <- cbind(array, array, array).

Is there a more elegant way of doing this?

I've tried

matrix <- cbind(rep(array, times=x)) and matrix <- rep(cbind(array), times = 5)

but it didn't work.

Thanks.
__
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.