[R] Making 2 dimensional vector from the 3 dimensional one

Jim Lemon drjimlemon at gmail.com
Fri Jul 14 23:59:32 CEST 2017


Hi Gabi,
Let's say you have something like this:

gc_array<-array(1:27,c(3,3,3))
> gc_array
, , 1

    [,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
[3,]    3    6    9

, , 2

    [,1] [,2] [,3]
[1,]   10   13   16
[2,]   11   14   17
[3,]   12   15   18

, , 3

    [,1] [,2] [,3]
[1,]   19   22   25
[2,]   20   23   26
[3,]   21   24   27

You seem to want to collapse this into a two dimensional array using
the values in the three dimensional array. For instance, if you want
to collapse in the third dimension by summing the values in each 2D
"slice":

> gc_array[,,1]+gc_array[,,2]+gc_array[,,3]
    [,1] [,2] [,3]
[1,]   30   39   48
[2,]   33   42   51
[3,]   36   45   54

The problem is working out whether the result means what you want. If
the first two dimensions were geographic coordinates and the third
contained a series of measurements over time, then you would have the
aggregate of those measures over time. Is this what you are trying to
do?

Jim

On Fri, Jul 14, 2017 at 7:43 PM, Csima, Gabriella
<gabriella.csima at metoffice.gov.uk> wrote:
> Hi All,
> I want to make a 1 dimension vector from the first two dimensions of a 3 dimension array, so make a 2 dimension vector from a 3-dimension one, with "fusing" (making as.vector) the first two dimensions.
> It seems to be very easy, but I cannot find the solution, I mean it would very strange, that I would do taking the single 1 dimensional vectors from the 3 dimensional one, make one vector from the first two vectors and make two dimension from the original 3rd one and this new one, but  I think there would be an easier way that I do not find.
> Could you help me, please?
> Thanks very much,
> Gabi
>
>
>         [[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
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list