Dear Steve,

Can you show us a small sample of your two data frames (maybe the top twenty
or so rows)? Maybe things will become clearer then. I don't think 'unique'
will help you very much with this. What you can do alternatively (though
less elegantly!) do is use a 'for' loop. This would probably look something
like:

common.rows <- matrix(NA, nrow = nrow(dataframe1), ncol = ncol(dataframe1))
for (s in 1:nrow(common.rows)){
for (i in 1:nrow(dataframe1)){
for (j in 1:nrow(dataframe2)){
if(dataframe1[i,1] == dataframe[j,1]){
if(dataframe1[i,2] == dataframe[j,2]){
common.rows[s,] <- dataframe1[i,]
}}
}}}
You will then have to make a new dataframe from common.rows which removes
all the extra NAs.
As you can see, very inelegant and quite horrible!

I haven't tried this on anything yet, so not 100 per cent sure it will work,
but I am sure 'intersect' will help. Maybe I can try with some of your data,
if you're willing.

Cheers,
Umesh

On Tue, Apr 28, 2009 at 3:19 PM, Steve Murray <smurray...@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.sriniva...@gmail.com
> > To: smurray...@hotmail.com
> > CC: r-help@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@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.
> >
> >
>
> _________________________________________________________________
> Beyond Hotmail — see what else you can do with Windows Live.
> http://clk.atdmt.com/UKM/go/134665375/direct/01/
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to