Skip to content
Prev 301766 / 398503 Next

Appending the column names

You can't always get what you want (a data.frame with two sets of column
headings), but you do have several options. Maybe they will help you think
about what you are trying to do.

Given X and Y as Arun provided earlier, you can create Z
Summary  G  Y  R
1     Acc 12 12 13
2     Bcc 11 14 15
3     Ccc 13 15 16
4 Summary  G  Y  R
5     Acc 10 11 12
6     Bcc 13 12 11
7     Ccc 11 16 20

Which is a data.frame, but all the variables are character and the second
set of column headings is just row #4.

Or a list consisting of two data.frames
$X
  Summary  G  Y  R
1     Acc 12 12 13
2     Bcc 11 14 15
3     Ccc 13 15 16

$Y
  Summary  G  Y  R
1     Acc 10 11 12
2     Bcc 13 12 11
3     Ccc 11 16 20

Now each data.frame is preserved as a member of the list ListXY.

Or a single data frame that keeps track of where each row comes from by
adding a column called Group:
Group Summary  G  Y  R
1     X     Acc 12 12 13
2     X     Bcc 11 14 15
3     X     Ccc 13 15 16
4     Y     Acc 10 11 12
5     Y     Bcc 13 12 11
6     Y     Ccc 11 16 20

You just might find that one of these is what you need.

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352