Making 2 dimensional vector from the 3 dimensional one

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Making 2 dimensional vector from the 3 dimensional one

Csima, Gabriella
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]]

______________________________________________
[hidden email] 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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Making 2 dimensional vector from the 3 dimensional one

Rolf Turner

On 14/07/17 21:43, Csima, Gabriella 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,

(1) Please avoid posting in HTML (although no great harm was done in
this instance).  This is a plain text mailing list, and HTML often makes
a mess.

(2) Spend some time learning R (e.g. read "An Introduction to R" from
the R web site).  In particular learn about array indexing.

(3) It is not *at all* clear to me what you actually want to do.  A
simple example of what you've got and what you want to get would help.

(4) What on earth do you mean by "a 1 dimension vector"?  A
1 dimensional vector is a scalar.  I can't believe that this is actually
what you are talking about.  Please clarify.

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

______________________________________________
[hidden email] 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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Making 2 dimensional vector from the 3 dimensional one

Jim Lemon-4
In reply to this post by Csima, Gabriella
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
<[hidden email]> 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]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Making 2 dimensional vector from the 3 dimensional one

Bert Gunter-2
In reply to this post by Csima, Gabriella
Like this ?

y <- array(1:24, dim = 2:4)
yy <- array(y, dim = c(6,4))


> y
, , 1

     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

, , 2

     [,1] [,2] [,3]
[1,]    7    9   11
[2,]    8   10   12

, , 3

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

, , 4

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

> yy
     [,1] [,2] [,3] [,4]
[1,]    1    7   13   19
[2,]    2    8   14   20
[3,]    3    9   15   21
[4,]    4   10   16   22
[5,]    5   11   17   23
[6,]    6   12   18   24


Explanation: An array is simply a vector with a "dim" attribute,
inexed in column major order.  See an Intro to R (ships with R) or any
good R tutorial (e.g. on the web) for details.


Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Jul 14, 2017 at 2:43 AM, Csima, Gabriella
<[hidden email]> 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]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Loading...