[R] changing the dimensions of a matrix in a real specific way

Sarah Goslee sarah.goslee at gmail.com
Thu Mar 17 13:37:34 CET 2011


matrix(a, ncol=3, nrow=4, byrow=TRUE)

or

> dim(a) <- c(3,4)
> a <- t(a)
> a
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    4    5    6
[3,]    7    8    9
[4,]   10   11   12

Depending on the context of the problem.

Sarah

On Thu, Mar 17, 2011 at 7:59 AM, Bodnar Laszlo EB_HU
<Laszlo.Bodnar at erstebank.hu> wrote:
> Hi again,
>
> I'd like to ask you a question again.
>
> I have a matrix like this:
> a <-matrix(c(1,2,3,4,5,6,7,8,9,10,11,12))
> a
>
>      [,1]
>  [1,]    1
>  [2,]    2
>  [3,]    3
>  [4,]    4
>  [5,]    5
>  [6,]    6
>  [7,]    7
>  [8,]    8
>  [9,]    9
> [10,]   10
> [11,]   11
> [12,]   12
>
> Is there a proper way to change the dimensions of this matrix so that I'll get this as a result:
>     [,1] [,2] [,3]
> [1,]   1    2    3
> [2,]   4    5    6
> [3,]   7    8    9
> [4,]  10   11   12
>
> Thank you very much and have a pleasant day,
> Laszlo
>

-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list