[R] Split a row vector into columns

Peter Maclean pmaclean2011 at yahoo.com
Wed Jul 6 23:51:50 CEST 2011


That is what I wanted
 Peter Maclean
Department of Economics
UDSM 



----- Original Message ----
From: Sarah Goslee <sarah.goslee at gmail.com>
To: Peter Maclean <pmaclean2011 at yahoo.com>
Cc: r-help at r-project.org
Sent: Wed, July 6, 2011 1:15:31 PM
Subject: Re: [R] Split a row vector into columns

You mean like:
> myvec <- c(1,2,3,1,2,3,1,2,3)
> myvec
[1] 1 2 3 1 2 3 1 2 3
> matrix(myvec, ncol=3, byrow=TRUE)
    [,1] [,2] [,3]
[1,]    1    2    3
[2,]    1    2    3
[3,]    1    2    3
>

Or do you actually have more complex requirements?

Sarah


On Wed, Jul 6, 2011 at 2:06 PM, Peter Maclean <pmaclean2011 at yahoo.com> wrote:
> I want to create columns from this row vector. From:
>     x1 x2 x3 x1 x2 x3 x1 x2 x3
>      1  2 3  1  2  3  1   2  3
>
> to:
> x1 x2 x3
> 1  2   3
> 1  2   3
> 1  2   3 Peter Maclean
> Department of Economics
> UDSM
>


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




More information about the R-help mailing list