[R] Making 2 dimensional vector from the 3 dimensional one
Bert Gunter
bgunter.4567 at gmail.com
Sat Jul 15 00:04:34 CEST 2017
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
<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