Skip to content

Splitting an array into two - alternate columns

1 message · Ross Ihaka

#
On Fri, Nov 24, 2000 at 12:46:37AM +0000, Phil Rhoades wrote:
I'm a big fan of brute force and ignorance!

	asplit <- 
	function(X)
	list(odd = x[,seq(1, ncol(x), by = 2)],
	     even = x[,seq(2, ncol(x), by = 2)])

	> x <- matrix(1:10,nr=2)
	> x
	     [,1] [,2] [,3] [,4] [,5]
	[1,]    1    3    5    7    9
	[2,]    2    4    6    8   10
	> asplit(x)
	$odd
	     [,1] [,2] [,3]
	[1,]    1    5    9
	[2,]    2    6   10
	
	$even
	     [,1] [,2]
	[1,]    3    7
	[2,]    4    8
	
Ross
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._