[R] stacking data.frame in a list

Danardono daodao99 at student.umu.se
Wed Sep 26 16:40:17 CEST 2001


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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list