[R] help with combining data frames

Martin Maechler maechler at stat.math.ethz.ch
Wed Mar 6 14:16:58 CET 2002

>>>>> "Frank" == Frank Mattes <list_server2001 at yahoo.com> writes:

    Frank> Dear R user, I'm relative new and need some help /
    Frank> advise from you. I have organised my data in several
    Frank> frames, mainly because the data came from different
    Frank> sources. One common variable in all data frames is
    Frank> the day post transplantation. I would like to combine
    Frank> the data frame to one big data frame which contains
    Frank> all the data, however no duplicate rows should occour
    Frank> (only one row for one day)

    Frank> Here an example which illustrates what I would like
    Frank> to do:

    Frank> Frame 1
    Frank> Day   Hb   wbc
    Frank> 1       10    4
    Frank> 3       11    7
    Frank> 5        9     6

    Frank> Frame 2

    Frank> Day   ALT
    Frank> 1        60
    Frank> 2        70
    Frank> 4        50
    Frank> 5        80

    Frank> Combined

    Frank> Day   Hb   wbc   ALT
    Frank> 1       10      4     60
    Frank> 2        NA    NA    70
    Frank> 3       11      7     NA
    Frank> 4        NA    NA    50
    Frank> 5         9       6     80

    Frank> Does anyone know if this can be done,

"if" is not the question with R -- it's a full programming language --
rather ``how easy''.  
Answer (in this case "quite easy"):

   fr12 <-  merge(frame1, frame2)

should work (using the merge method `merge.data.frame' --
	     look at its help page for options!)

    Frank> or is it better not to combine  the frames ?

(this depends on what you want to do with it; 
 I think I *would* want a combined data frame (and still keep the single ones))

Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><
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