[R] Finding rows common to two datasets

jim holtman jholtman at gmail.com
Tue Apr 28 12:17:51 CEST 2009


You are missing a comma:

common <- intersect(data_frame_x[,c("Latitude", "Longitude")],
data_frame_y[,c("Latitude","Longitude")])

On Tue, Apr 28, 2009 at 5:49 AM, Steve Murray <smurray444 at hotmail.com> wrote:
>
> 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.
>>
>>
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list