[R] need help combining two datasets

Dieter Menne dieter.menne at menne-biomed.de
Wed Jan 28 09:05:39 CET 2009


Adam D. I. Kramer <adik <at> ilovebacon.org> writes:

> 
> You probably want the merge function.
> 
> ?merge
> 
> On Wed, 28 Jan 2009, Somani, Dinesh K wrote:
> 
> > I have two CSV files, one with daily stock returns using method A {date,
> > stock, returnA, some uninteresting columns}, and another with method B
> > {date, stock, returnB, more columns}.  Both have different sets of stocks.
> >
> > I want to combine the two into a single data table, so that I can run some
> > analyses for the overlapping date ranges and stocks.  I know how to do
> > this using a database but is there an equivalent way to perform a similar
> > kind of join in R?

I think the merge function will not do it here, because he has different sets of
stock. I would suggest the following

-- Read in A.CSV and B.CSV into data frames a and b
-- Remove uninteresing columns 
-- a$method = 'a'
-- b$method = 'b'
-- rename column returnA and return B to "return"
-- rbind(a,b)

Dieter




More information about the R-help mailing list