# [R] 3D matrix

David Khabie-Zeitoune dave at evocapital.com
Tue Aug 5 19:24:11 CEST 2003

```As previous replies have suggested -- you could use an "array"
E.g.

> X = array(0, dim=c(100,12,12))

Then X[i, , ] returns the i-th 12 by 12 matrix "slice" in this array,
e.g.

> X[1, ,]

[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
[1,]    0    0    0    0    0    0    0    0    0     0     0     0
[2,]    0    0    0    0    0    0    0    0    0     0     0     0
[3,]    0    0    0    0    0    0    0    0    0     0     0     0
[4,]    0    0    0    0    0    0    0    0    0     0     0     0
[5,]    0    0    0    0    0    0    0    0    0     0     0     0
[6,]    0    0    0    0    0    0    0    0    0     0     0     0
[7,]    0    0    0    0    0    0    0    0    0     0     0     0
[8,]    0    0    0    0    0    0    0    0    0     0     0     0
[9,]    0    0    0    0    0    0    0    0    0     0     0     0
[10,]    0    0    0    0    0    0    0    0    0     0     0     0
[11,]    0    0    0    0    0    0    0    0    0     0     0     0
[12,]    0    0    0    0    0    0    0    0    0     0     0     0

-----Original Message-----
From: Marcel Vieira [mailto:mtolvieira at msn.com]
Sent: 05 August 2003 17:43
To: ripley at stats.ox.ac.uk
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] 3D matrix

Dear all,

I think I need to explain what I want to do.

I want to create 100 matrices with size 12x12.

The following program is not working...
nk <- 100
for (i in 1:nk) {
case[i]<-matrix(0,12,12)
}

Thanks a lot.
Regards.
Marcel

>From: Prof Brian Ripley <ripley at stats.ox.ac.uk>
>
>Do you mean a 3-dimensional array?  If so see the help for array(). In
>S/R terminology, a matrix is 2D, by definition.
>
>On Tue, 5 Aug 2003, Marcel Vieira wrote:
>
> > Is it possible to define a 3 dimension matrix in R? (without using
> > list - if possible)
>
>--
>Brian D. Ripley,                  ripley at stats.ox.ac.uk
>Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
>University of Oxford,             Tel:  +44 1865 272861 (self)
>1 South Parks Road,                     +44 1865 272866 (PA)
>Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

```