one long column of data -> three small columns

7 messages Options
Embed this post
Permalink
DispersionMap

one long column of data -> three small columns

Reply Threaded More More options
Print post
Permalink
say i have a column of data like this...

2
3
4
2
1
6
6
4
7

and i want it in three columns like this

226
314
467

...so i can make a contour plot.


How do i do this?
Jorge Ivan Velez

Re: one long column of data -> three small columns

Reply Threaded More More options
Print post
Permalink
Hi french,

Here is a suggestion:

x <- c(2, 3, 4, 2, 1, 6, 6, 4, 7)
 matrix(x, ncol = 3)
#   [,1] [,2] [,3]
# [1,]    2    2    6
# [2,]    3    1    4
# [3,]    4    6    7

with x the column of data you have.

HTH,
Jorge


On Tue, Nov 3, 2009 at 2:05 PM, frenchcr <> wrote:

>
> say i have a column of data like this...
>
> 2
> 3
> 4
> 2
> 1
> 6
> 6
> 4
> 7
>
> and i want it in three columns like this
>
> 226
> 314
> 467
>
> ...so i can make a contour plot.
>
>
> How do i do this?
> --
> View this message in context:
> http://old.nabble.com/one-long-column-of-data--%3E-three-small-columns-tp26163165p26163165.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [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.
>

        [[alternative HTML version deleted]]

______________________________________________
[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.
Peter Alspach-2

Re: one long column of data -> three small columns

Reply Threaded More More options
Print post
Permalink
In reply to this post by DispersionMap
Tena koe

?matrix

The exact syntax will depend on the class of your 'column of data'.  If
it is a dataframe, for example, then try

matrix(yourData[,1], 3, 3)

HTH ...

Peter Alspach

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of frenchcr
> Sent: Wednesday, 4 November 2009 8:06 a.m.
> To: [hidden email]
> Subject: [R] one long column of data -> three small columns
>
>
> say i have a column of data like this...
>
> 2
> 3
> 4
> 2
> 1
> 6
> 6
> 4
> 7
>
> and i want it in three columns like this
>
> 226
> 314
> 467
>
> ...so i can make a contour plot.
>
>
> How do i do this?
> --
> View this message in context:
> http://old.nabble.com/one-long-column-of-data--%3E-three-small
> -columns-tp26163165p26163165.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [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.
Jorge Ivan Velez

Re: one long column of data -> three small columns

Reply Threaded More More options
Print post
Permalink
In reply to this post by DispersionMap
Hi french,

Here is a suggestion:

x <- c(2, 3, 4, 2, 1, 6, 6, 4, 7)
 matrix(x, ncol = 3)
#   [,1] [,2] [,3]
# [1,]    2    2    6
# [2,]    3    1    4
# [3,]    4    6    7

HTH,
Jorge


On Tue, Nov 3, 2009 at 2:05 PM, frenchcr <> wrote:

>
> say i have a column of data like this...
>
> 2
> 3
> 4
> 2
> 1
> 6
> 6
> 4
> 7
>
> and i want it in three columns like this
>
> 226
> 314
> 467
>
> ...so i can make a contour plot.
>
>
> How do i do this?
> --
> View this message in context:
> http://old.nabble.com/one-long-column-of-data--%3E-three-small-columns-tp26163165p26163165.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [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.
>

        [[alternative HTML version deleted]]

______________________________________________
[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.
DispersionMap

Re: one long column of data -> three small columns

Reply Threaded More More options
Print post
Permalink
In reply to this post by DispersionMap

frenchcr wrote:
say i have a column of data like this...

2
3
4
2
1
6
6
4
7

and i want it in three columns like this

226
314
467

...so i can make a contour plot.


How do i do this?
ok, so matrix(x, 3, 3) works.

what if i have

a
b
c
a
c
a
c

and want

a b c
a   c
a   c

??
Patrick Connolly-4

Re: one long column of data -> three small columns

Reply Threaded More More options
Print post
Permalink
On Tue, 03-Nov-2009 at 12:26PM -0800, frenchcr wrote:


|> > How do i do this?
|> >
|>
|> ok, so matrix(x, 3, 3) works.
|>
|> what if i have
|>
|> a
|> b
|> c
|> a
|> c
|> a
|> c
|>
|> and want
|>
|> a b c
|> a   c
|> a   c
|>
|> ??

Hint 1: A matrix can use characters or numerics
Hint 2: "" can be considered as a character.

HTH

--
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.  
   ___    Patrick Connolly  
 {~._.~}                   Great minds discuss ideas    
 _( Y )_           Average minds discuss events
(:_~*~_:)                  Small minds discuss people  
 (_)-(_)                        ..... Eleanor Roosevelt
         
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

______________________________________________
[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.
MORNEAU François

Re: one long column of data -> three small columns

Reply Threaded More More options
Print post
Permalink
In reply to this post by DispersionMap
Hello ?,
Have a look at ?matrix
        matrix(c(2, 3, 4, 2, 1, 6, 6, 4, 7), ncol = 3)
François

-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de frenchcr
Envoyé : mardi 3 novembre 2009 20:06
À : [hidden email]
Objet : [R] one long column of data -> three small columns


say i have a column of data like this...

2
3
4
2
1
6
6
4
7

and i want it in three columns like this

226
314
467

...so i can make a contour plot.


How do i do this?
--
View this message in context: http://old.nabble.com/one-long-column-of-data--%3E-three-small-columns-tp26163165p26163165.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
[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.