Comparing lat long of two locations in data frame

while comparing lat long of two locations it comparing only observation to observation not the complete data frame as in example it gives 2 common lat and longs however there are more than 2 please guide.

Lat= function(){
      a = runif(10,29.00,34.00)
      a= round(a)
      return(a)
    }
    
    Long= function(){
      b = runif(10,69.00,72.00)
      b= round(b)
      return(b)
    }
    onlineloc=data.frame(LAT=Lat(),LONG=Long())
    onlineloc
#>    LAT LONG
#> 1   33   70
#> 2   34   71
#> 3   30   70
#> 4   32   72
#> 5   30   72
#> 6   34   70
#> 7   31   71
#> 8   29   71
#> 9   31   71
#> 10  30   70
    instore=data.frame(LAT=Lat(),LONG=Long())
    instore
#>    LAT LONG
#> 1   33   71
#> 2   32   70
#> 3   33   71
#> 4   33   71
#> 5   30   70
#> 6   34   72
#> 7   33   70
#> 8   31   71
#> 9   31   71
#> 10  30   70
    
    #set.seed(100)
    
    Z= onlineloc == instore
    Z
#>         LAT  LONG
#>  [1,]  TRUE FALSE
#>  [2,] FALSE FALSE
#>  [3,] FALSE FALSE
#>  [4,] FALSE FALSE
#>  [5,]  TRUE FALSE
#>  [6,]  TRUE FALSE
#>  [7,] FALSE FALSE
#>  [8,] FALSE  TRUE
#>  [9,]  TRUE  TRUE
#> [10,]  TRUE  TRUE
    p=print(instore[Z[,1] & Z[,2], ])
#>    LAT LONG
#> 9   31   71
#> 10  30   70
    nrow(p)
#> [1] 2

Created on 2020-01-26 by the reprex package (v0.3.0)

You don't really have a question. And in your statement above, it sounds like you are wanting to compare locations, but you are not using any comparison operators <,>,=,!=... you may always want to look into the function

unique() 

to help find unique locations

i think uniqe() is used for one data frame(for comparing 2 columns within data frame) but i want to compare 2 data frames(with 2 colums of lat and long) with each other that y i used following comparison in reprex
Z= onlineloc == instore

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.