# [R] creating cubes

Dalthorp, Daniel ddalthorp at usgs.gov
Sat Jan 16 00:17:02 CET 2016

```One possibility is to arrange it as a 3-dimensional array with two 5 x 5
matrices (i.e. a 5 x 5 x 2 array):

arrD3<-array(dim=c(5,5,2))

# the first matrix is (e.g.) random normal deviates:
mat1<-matrix(rnorm(25),nrow=5,ncol=5)

# the second matrix is (e.g.) random uniform deviates:
mat2<-matrix(runif(25),nrow=5,ncol=5)

arrD3[,,1]<-mat1
arrD3[,,2]<-mat2

# to see what it looks like:
arrD3

On Fri, Jan 15, 2016 at 2:57 PM, Matteo Richiardi <
matteo.richiardi at gmail.com> wrote:

> Hi Daniel,
> thanks for your answer. How can I populate the array with the
> matrixes? Suppose I want to populate it with 10 matrixes
>
> matrix(NA,5,5)
>
> Matteo
>
>
> On 15 January 2016 at 22:26, Dalthorp, Daniel <ddalthorp at usgs.gov> wrote:
> > How about: D<-array(dim=c(d1, d2, d3))?
> >
> >
> >
> > On Fri, Jan 15, 2016 at 2:20 PM, Matteo Richiardi
> > <matteo.richiardi at gmail.com> wrote:
> >>
> >> What is the best way to store data in a cube? That is, I need to create
> a
> >> data structure D with three indexes, say i,j,h, so that I can access
> each
> >> data point D[i,j,h], and visualise sections like D[i,j,] or D[,,h].
> >>
> >> I have tried to create an array of matrixes:
> >>
> >> D <-matrix(matrix(NA,i,j),h)
> >>
> >> but then D[i] returns a number, and not a matrix.
> >>
> >> I imagine this is a dummy question, but I did search for an answer on
> >> various R help sites, and found nothing straightforward. Being an
> >> inexperienced R user, I prefer a simple solution, even at some
> efficiency
> >> cost.
> >>
> >> Many thanks for your help.
> >> Matteo
> >>
> >>         [[alternative HTML version deleted]]
> >>
> >> ______________________________________________
> >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >
> >
> >
> >
> > --
> > Dan Dalthorp, PhD
> > USGS Forest and Rangeland Ecosystem Science Center
> > Forest Sciences Lab, Rm 189
> > 3200 SW Jefferson Way
> > Corvallis, OR 97331
> > ph: 541-750-0953
> > ddalthorp at usgs.gov
> >
>

--
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalthorp at usgs.gov

[[alternative HTML version deleted]]

```