s-news
[Top] [All Lists]

Stacking datasets

To: s-news@lists.biostat.wustl.edu
Subject: Stacking datasets
From: Thom Burnett <Thom.Burnett@cognigencorp.com>
Date: Thu, 30 Sep 2004 08:45:21 -0400
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113

How do I put one data.frame 'on top of' another?
That is the new number of rows must equal the sum of the two input data frames.

rbind() does exactly this when the datasets match columns.
I need to stack data.frames where the columns don't match completely and put missing places where the new column was unavailable before.

A simple example:
top is:
ID WEIGHT
1    66.3
2    52.6

bottom is:

ID  BMI
3      21.6
4       23.1

The combined result should be:
all
ID WEIGHT  BMI
1    66.3          -
2     52.6         -
3    -              21.6
4    -              23.1

Note that nrow(all) == nrow(top) + nrow(bottom)
and
columns are the union of the two inputs.

Any suggestions on how to accomplish this would be appreciated.

<Prev in Thread] Current Thread [Next in Thread>