[R] Subarrays

From: Gunnar Hellmund <ghellmund_at_gmail.com>
Date: Sat 30 Apr 2005 - 01:33:36 EST


Define an array

> v<-1:256
> dim(v)<-rep(4,4)

Subarrays can be obtained as follows:

> v[3,2,,2]

[1] 71 87 103 119
> v[3,,,2]

     [,1] [,2] [,3] [,4]

[1,]   67   83   99  115
[2,]   71   87  103  119
[3,]   75   91  107  123
[4,]   79   95  111  127

In the general case this procedure is very tedious.

Given an array
A, dim(A)=(dim_1,dim_2,...,dim_d)
and two vectors
v1=(n_i1,...n_ik), v2=(int_1,...,int_k) ('marginals' and relevant 'interval numbers')
is there a smart way to obtain
A[,...,int_1,....,int_2,....,....,int_k,....] ?

Best wishes
Gunnar Hellmund



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Apr 30 01:41:16 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:31 EST