Re: [R] Joining Dataframes

From: Don MacQueen <>
Date: Wed 05 Oct 2005 - 06:51:26 EST

It appears that you want to match rows by date. It also looks like your date information is in the row names, only, if the layout of your example can be trusted.

The help for merge says this:

     "By default the data frames are merged on the columns with names they both have..."
but the column you want to merge by, date, is not in either dataframe. So, obviously, it can't merge on date. Also, since your example has other columns with the same name that you do not want to merge on, you will have to tell it explicitly what columns to use for the merge.

So, assuming I've interpreted your example correctly, try this:

   (1) get your dates into a column
   (2) use the 'by' argument of merge to force it to merge on date only.

            merge(species1.effort, species2.effort, by='date')


At 11:37 AM -0800 10/4/05, Matt Goff wrote:
>I am attempting to join several dataframes that summarize sampling effort
>for different samples into one large data.frame/table.
>I have looked at the merge command, but have not been clever enough to
>figure out how to get it to do what I want.
>A simplified example of what I am trying to do:
>The dataframes I have look like this (they were generated using the table
> site1 site2 site3
>date1 5 5 5
>date2 4 5 5
>date3 4 5 5
> site1 site2 site3
>date1 7 8 6
>date3 8 7 8
>date4 8 8 8
>I would like to join these into a table that looks something like this:
> sp1.site1 sp1.site2 sp1.site3 sp2.site1 sp2.site2
>date1 5 5 5 7
>8 6
>date2 4 5 5 NA
>date3 4 5 5 8
>7 8
>date4 NA NA NA 8 8
>I have many more dates and species, but I assume whatever method works for
>this small example, would work for larger cases.
>Matt Goff
> mailing list
>PLEASE do read the posting guide!

Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA

______________________________________________ mailing list
PLEASE do read the posting guide!
Received on Wed Oct 05 07:26:36 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:18:24 EST