[R] stacking data.frame in a list

Warnes, Gregory R gregory_r_warnes at groton.pfizer.com
Thu Sep 27 21:42:54 CEST 2001


Alternatively, use the concat() function from the gregmisc library:

> library(gregmisc)
Attaching package `gregmisc':

[warnings omitted]]

> concat(x[[1]],x[[2]],names=names(x))
   age.day state  source
1       81     0  772307
2      141     0  772307
3      234     0  772307
4      321     0  772307
5      437     0  772307
6      499     0  772307
7      601     1  772307
8      689     1  772307
9      801     0  772307
10     884    99  772307
11     961     1  772307
12      80     0 1084506
13     148     0 1084506
14     249    99 1084506
15     344    99 1084506

-Greg



 >  -----Original Message-----
 >  From: Danardono [mailto:daodao99 at student.umu.se]
 >  Sent: Wednesday, September 26, 2001 10:40 AM
 >  To: r-help at stat.math.ethz.ch
 >  Subject: [R] stacking data.frame in a list
 >  
 >  
 >  Hello,
 >  
 >  Given this list object x,
 >  x <-
 >  structure(list("772307" = structure(list(age.day = c(81, 141,
 >  234, 321, 437, 499, 601, 689, 801, 884, 961), state = c(0, 0,
 >  0, 0, 0, 0, 1, 1, 0, 99, 1)), .Names = c("age.day", 
 >  "state"), class =
 >  "data.frame", row.names = c("1",
 >  "2", "3", "4", "5", "6", "7", "8", "9", "10", "11")), "1084506" =
 >  structure(list(
 >      age.day = c(80, 148, 249, 344), state = c(0, 0, 99, 
 >  99)), .Names =
 >  c("age.day",
 >  "state"), class = "data.frame", row.names = c("1", "2", "3",
 >  "4"))), .Names = c("772307", "1084506"))
 >  
 >  that looks like this:
 >  > x
 >  $"772307"
 >     age.day state
 >  1       81     0
 >  2      141     0
 >  3      234     0
 >  4      321     0
 >  5      437     0
 >  6      499     0
 >  7      601     1
 >  8      689     1
 >  9      801     0
 >  10     884    99
 >  11     961     1
 >  
 >  $"1084506"
 >    age.day state
 >  1      80     0
 >  2     148     0
 >  3     249    99
 >  4     344    99
 >  
 >  How to stack "772307" and "1084506", preferrably with "772307" and
 >  $"1084506" as indicator (the original data consists of 
 >  thousands "ID" such
 >  "772307" and "1084506")?
 >  The expected result will be like,
 >  ID       age.day state
 >  772307       81     0
 >  772307      141     0
 >  772307      234     0
 >  772307      321     0
 >  772307      437     0
 >  772307      499     0
 >  772307      601     1
 >  772307      689     1
 >  772307      801     0
 >  772307      884    99
 >  772307      961     1
 >  1084506      80     0
 >  1084506     148     0
 >  1084506     249    99
 >  1084506     344    99
 >  
 >  Thank you.
 >  Danar.
 >  
 >  
 >  
 >  
 >  -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
 >  -.-.-.-.-.-.-.-.-.-
 >  r-help mailing list -- Read 
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._


LEGAL NOTICE
Unless expressly stated otherwise, this message is confidential and may be privileged. It is intended for the addressee(s) only. Access to this E-mail by anyone else is unauthorized. If you are not an addressee, any disclosure or copying of the contents of this E-mail or any action taken (or not taken) in reliance on it is unauthorized and may be unlawful. If you are not an addressee, please inform the sender immediately.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list