[R] Merge two data frames and find common values and non-matching values

Sarah Goslee sarah.goslee at gmail.com
Mon Oct 3 21:27:16 CEST 2011


Hi,


On Mon, Oct 3, 2011 at 1:54 PM, francy <francy.casalino at gmail.com> wrote:
> Hi,
>
> I am trying to find a function to match two data frames of different lengths
> for one field only.
> So, for example,
> df1 is:
>
> Name Position location
> francesca A 75
> cristina B 36
>
> And df2 is:
>
> location Country
> 75 UK
> 56 Austria
>
> And I would like to match on "Location" and the output to be something like:


Sounds like you need merge() (just as in your subject line!).

> Name Position Location Match
> francesca A 75 1
> cristina B 36 0
>
> I have tried with the function 'match' or with:
> subset(df1, location %in% df2)
> But it does not work.
>
> Could you please help me figure out how to do this?
>

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list