[R] Splitting an array into two - alternate columns
Ross Ihaka
ihaka at stat.auckland.ac.nz
Thu Nov 23 21:39:50 CET 2000
On Fri, Nov 24, 2000 at 12:46:37AM +0000, Phil Rhoades wrote:
> I want to split an array (A1) into two arrays using alternate columns eg
>
> A2 would consist of:
>
> A1[,1], A1[,3], A1[,5], . .
>
> A3 would consist of:
>
> A1[,2], A1[,4], A1[,6], . .
>
> Anyone got a nice method?
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list