Re: Split a row vector into columns

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Split a row vector into columns

Peter Maclean
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

______________________________________________
[hidden email] mailing list
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.
Reply | Threaded
Open this post in threaded view
|

Re: Split a row vector into columns

Sarah Goslee
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 <[hidden email]> 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

______________________________________________
[hidden email] mailing list
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.
Reply | Threaded
Open this post in threaded view
|

Re: Split a row vector into columns

John Kane-2
In reply to this post by Peter Maclean
t(matrix(rep(1:3, 3), nrow=3))


--- On Wed, 7/6/11, Peter Maclean <[hidden email]> wrote:

> From: Peter Maclean <[hidden email]>
> Subject: Re: [R] Split a row vector into columns
> To: [hidden email]
> Received: Wednesday, July 6, 2011, 2:06 PM
> 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
>
> ______________________________________________
> [hidden email]
> mailing list
> 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
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.
Reply | Threaded
Open this post in threaded view
|

Re: Split a row vector into columns

Peter Maclean
In reply to this post by Sarah Goslee
That is what I wanted
 Peter Maclean
Department of Economics
UDSM



----- Original Message ----
From: Sarah Goslee <[hidden email]>
To: Peter Maclean <[hidden email]>
Cc: [hidden email]
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 <[hidden email]> 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


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