I have two CSV files (exported from Excel), say file1 and file2.
The have the same number of rows, and each has several columns,
with names on the first line; and some of the columns in file1
are repeated in file2.
Using the "foreign" package, I can read these in separately
to dataframes say d1 and d2 with
> d1<-read.csv("file1")
> d2<-read.csv("file2")
Now I would like to combine these into a single dataframe D,
notionally
D <- "d1 on the left, d2 on the right"
which contains all the columns except that duplicates only occur
once (and, preferably, in the order of occurrence on d1 -- i.e.
remove them from d2 if already dound in d1).
Any tips for how to do this slickly?
With thanks,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 167 1972
Date: 17-Dec-02 Time: 15:47:27
------------------------------ XFMail ------------------------------
Quick tip please!
4 messages · (Ted Harding), Ben Bolker, Ulises M. Alvarez +1 more
Maybe data.frame(d1,d2[!names(d2) %in% names(d1)]) ?
On Tue, 17 Dec 2002 Ted.Harding at nessie.mcc.ac.uk wrote:
I have two CSV files (exported from Excel), say file1 and file2. The have the same number of rows, and each has several columns, with names on the first line; and some of the columns in file1 are repeated in file2. Using the "foreign" package, I can read these in separately to dataframes say d1 and d2 with
> d1<-read.csv("file1")
> d2<-read.csv("file2")
Now I would like to combine these into a single dataframe D, notionally D <- "d1 on the left, d2 on the right" which contains all the columns except that duplicates only occur once (and, preferably, in the order of occurrence on d1 -- i.e. remove them from d2 if already dound in d1). Any tips for how to do this slickly? With thanks, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 167 1972 Date: 17-Dec-02 Time: 15:47:27 ------------------------------ XFMail ------------------------------
______________________________________________ R-help at stat.math.ethz.ch mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
318 Carr Hall bolker at zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704
Ted: Take a look at ?merge Good look
On Tue, 17 Dec 2002 Ted.Harding at nessie.mcc.ac.uk wrote:
I have two CSV files (exported from Excel), say file1 and file2. The have the same number of rows, and each has several columns, with names on the first line; and some of the columns in file1 are repeated in file2. Using the "foreign" package, I can read these in separately to dataframes say d1 and d2 with
> d1<-read.csv("file1")
> d2<-read.csv("file2")
Now I would like to combine these into a single dataframe D, notionally D <- "d1 on the left, d2 on the right" which contains all the columns except that duplicates only occur once (and, preferably, in the order of occurrence on d1 -- i.e. remove them from d2 if already dound in d1). Any tips for how to do this slickly? With thanks, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 167 1972 Date: 17-Dec-02 Time: 15:47:27 ------------------------------ XFMail ------------------------------
______________________________________________ R-help at stat.math.ethz.ch mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
Ulises M. Alvarez LAB. DE ONDAS DE CHOQUES FISICA APLICADA Y TECNOLOGIA AVANZADA UNAM umalvarez at fata.unam.mx
Hi, Please read "merge". Regards, Carlos. -----Mensaje original----- De: r-help-admin at stat.math.ethz.ch [mailto:r-help-admin at stat.math.ethz.ch]En nombre de Ben Bolker Enviado el: martes, 17 de diciembre de 2002 17:32 Para: Ted.Harding at nessie.mcc.ac.uk CC: r-help at stat.math.ethz.ch Asunto: Re: [R] Quick tip please! Maybe data.frame(d1,d2[!names(d2) %in% names(d1)]) ?
On Tue, 17 Dec 2002 Ted.Harding at nessie.mcc.ac.uk wrote:
I have two CSV files (exported from Excel), say file1 and file2. The have the same number of rows, and each has several columns, with names on the first line; and some of the columns in file1 are repeated in file2. Using the "foreign" package, I can read these in separately to dataframes say d1 and d2 with
> d1<-read.csv("file1")
> d2<-read.csv("file2")
Now I would like to combine these into a single dataframe D, notionally D <- "d1 on the left, d2 on the right" which contains all the columns except that duplicates only occur once (and, preferably, in the order of occurrence on d1 -- i.e. remove them from d2 if already dound in d1). Any tips for how to do this slickly? With thanks, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 167 1972 Date: 17-Dec-02 Time: 15:47:27 ------------------------------ XFMail ------------------------------
______________________________________________ R-help at stat.math.ethz.ch mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
318 Carr Hall bolker at zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704 ______________________________________________ R-help at stat.math.ethz.ch mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help _____ The information in this email is confidential and it may not be\ ... [[dropped]]