Converting from a dataset to a single "column"

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Converting from a dataset to a single "column"

R user-3
I have a dataset of 3 “columns” and 5 “rows”.

temp<-data.frame(col1=c(5,10,14,56,7),col2=c(4,2,8,3,34),col3=c(28,4,52,34,67))

I wish to convert this to a single “column”, with
column 1 on “top” and column 3 on “bottom”.

i.e.

5
10
14
56
7
4
2
8
3
34
28
4
52
34
67

Are there any functions that do this, and that will
work well on much larger datasets (e.g. 1000 rows,
6000 columns)?

______________________________________________
[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
Reply | Threaded
Open this post in threaded view
|

Re: Converting from a dataset to a single "column"

jholtman
?unlist

> temp<-data.frame
(col1=c(5,10,14,56,7),col2=c(4,2,8,3,34),col3=c(28,4,52,34,67))
> temp
  col1 col2 col3
1    5    4   28
2   10    2    4
3   14    8   52
4   56    3   34
5    7   34   67
> unlist(temp)
col11 col12 col13 col14 col15 col21 col22 col23 col24 col25 col31 col32
col33 col34 col35
    5    10    14    56     7     4     2     8     3    34    28     4
52    34    67
>



On 1/23/06, r user <[hidden email]> wrote:

>
> I have a dataset of 3 "columns" and 5 "rows".
>
> temp<-data.frame
> (col1=c(5,10,14,56,7),col2=c(4,2,8,3,34),col3=c(28,4,52,34,67))
>
> I wish to convert this to a single "column", with
> column 1 on "top" and column 3 on "bottom".
>
> i.e.
>
> 5
> 10
> 14
> 56
> 7
> 4
> 2
> 8
> 3
> 34
> 28
> 4
> 52
> 34
> 67
>
> Are there any functions that do this, and that will
> work well on much larger datasets (e.g. 1000 rows,
> 6000 columns)?
>
> ______________________________________________
> [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
>



--
Jim Holtman
Cincinnati, OH
+1 513 247 0281

What the problem you are trying to solve?

        [[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
Reply | Threaded
Open this post in threaded view
|

Re: Converting from a dataset to a single "column"

Peter Dalgaard
In reply to this post by R user-3
r user <[hidden email]> writes:

> I have a dataset of 3 “columns” and 5 “rows”.
>
> temp<-data.frame(col1=c(5,10,14,56,7),col2=c(4,2,8,3,34),col3=c(28,4,52,34,67))
>
> I wish to convert this to a single “column”, with
> column 1 on “top” and column 3 on “bottom”.
>
> i.e.
>
> 5
> 10
> 14
> 56
> 7
> 4
> 2
> 8
> 3
> 34
> 28
> 4
> 52
> 34
> 67
>
> Are there any functions that do this, and that will
> work well on much larger datasets (e.g. 1000 rows,
> 6000 columns)?

unlist(temp,use.names=FALSE)

Did you really mean "column" (as opposed to vector?), if so,

matrix(unlist(temp,use.names=FALSE))

--
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - ([hidden email])                  FAX: (+45) 35327907

______________________________________________
[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
Reply | Threaded
Open this post in threaded view
|

Re: Converting from a dataset to a single "column"

Gábor Csárdi-2
In reply to this post by R user-3
> temp<-data.frame(col1=c(5,10,14,56,7),col2=c(4,2,8,3,34),col3=c(28,4,52,34,67))
> temp
      col1 col2 col3
    1    5    4   28
    2   10    2    4
    3   14    8   52
    4   56    3   34
    5    7   34   67
> as.numeric(as.matrix(temp))
 [1]  5 10 14 56  7  4  2  8  3 34 28  4 52 34 67
             
Whether this works well enough:
             
> temp <- as.data.frame(matrix(1:(1000*6000), nr=1000))
> dim(temp)
  [1] 1000 6000
> date() ; num <- as.numeric(as.matrix(temp)) ; date()
  [1] "Mon Jan 23 19:40:25 2006"
  [1] "Mon Jan 23 19:40:25 2006"
> length(num)
  [1] 6000000
             
Gabor
             
On Mon, Jan 23, 2006 at 09:49:40AM -0800, r user wrote:

> I have a dataset of 3 “columns” and 5 “rows”.
>
> temp<-data.frame(col1=c(5,10,14,56,7),col2=c(4,2,8,3,34),col3=c(28,4,52,34,67))
>
> I wish to convert this to a single “column”, with
> column 1 on “top” and column 3 on “bottom”.
>
> i.e.
>
> 5
> 10
> 14
> 56
> 7
> 4
> 2
> 8
> 3
> 34
> 28
> 4
> 52
> 34
> 67
>
> Are there any functions that do this, and that will
> work well on much larger datasets (e.g. 1000 rows,
> 6000 columns)?
>
> ______________________________________________
> [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

--
Csardi Gabor <[hidden email]>    MTA RMKI, ELTE TTK

______________________________________________
[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
Reply | Threaded
Open this post in threaded view
|

Re: Converting from a dataset to a single "column"

PIKAL Petr
In reply to this post by R user-3
Hi

?stack and ?unlist are good starting points.

HTH
Petr


On 23 Jan 2006 at 9:49, r user wrote:

Date sent:       Mon, 23 Jan 2006 09:49:40 -0800 (PST)
From:           r user <[hidden email]>
To:             rhelp <[hidden email]>
Subject:         [R] Converting from a dataset to a single "column"

> I have a dataset of 3  columns  and 5  rows .
>
> temp<-data.frame(col1=c(5,10,14,56,7),col2=c(4,2,8,3,34),col3=c(28,4,5
> 2,34,67))
>
> I wish to convert this to a single  column , with
> column 1 on  top  and column 3 on  bottom .
>
> i.e.
>
> 5
> 10
> 14
> 56
> 7
> 4
> 2
> 8
> 3
> 34
> 28
> 4
> 52
> 34
> 67
>
> Are there any functions that do this, and that will
> work well on much larger datasets (e.g. 1000 rows,
> 6000 columns)?
>
> ______________________________________________
> [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

Petr Pikal
[hidden email]

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