[R] Finding rows common to two datasets

Steve Murray smurray444 at hotmail.com
Tue Apr 28 11:49:33 CEST 2009


Thanks for the reply, however, when I do the following command, I receive the message: 'data frame with 0 columns and 0 rows'. I've checked again though, and there should be several thousand rows where the Latitude and Longitude pairs are the same.

> common <- intersect(data_frame_x[c("Latitude", "Longitude")], data_frame_y[c("Latitude","Longitude")])
> common
data frame with 0 columns and 0 rows


Is there an obvious solution to this? Should I be using 'unique' instead, and if so, how would I get the above to correspond to this command?

Thanks,

Steve




________________________________
> Date: Tue, 28 Apr 2009 13:36:51 +0530
> Subject: Re: [R] Finding rows common to two datasets
> From: umesh.srinivasan at gmail.com
> To: smurray444 at hotmail.com
> CC: r-help at r-project.org
>
> Dear Steve,
>
> Try
>
> ? intersect
>
> and see if that might help.
>
> Cheers,
> Umesh
>
> On Tue, Apr 28, 2009 at 1:29 PM, Steve Murray> wrote:
>
>
>
> Dear all,
>
>
>
> I have 2 data frames, both with 14 columns of data and differing numbers of rows. The first two columns are 'Latitude' and 'Longitude'. I want to find the pairs of Latitude and Longitude coordinates which are common to both datasets, and output a new data frame which is composed of these coincident rows. I tried using the 'unique' command, but had difficulties interpreting the help file.
>
>
>
>
> Many thanks for any help offered,
>
>
>
> Steve
>
>
>
> ______________________________________________
>
> R-help at r-project.org mailing list
>
> https://stat.ethz.ch/mailman/listinfo/r-help
>
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>
> and provide commented, minimal, self-contained, reproducible code.
>
>




More information about the R-help mailing list