I want to calculate distance (in meters) between lat/long positions of my dataframe, but with this limitations: 1.- Only lat/long of the same CLIENTID, but all of the same between them. 2.- Generating a new dataframe (and export to CSV o XLS) for each CLIENTID
My data are stored as:
| CLIENT ID | HOUSE ID | LAT | LONG |
| 111111111 | xxx111   | xx.xx| xx.xx|
| 111111111 | xxx112   | xx.xx| xx.xx|
| 111111111 | xxx145   | xx.xx| xx.xx|
| 222222222 | xxx345   | xx.xx| xx.xx|
| 222222222 | xxx 666  | xx.xx| xx.xx|
What I need:
A CSV or XLS file named with CLIENTID (CLIENTID.csv) with this content:
| CLIENT ID | HOUSE ID1 | HOUSE ID 2| DISTANCE |
| 111111111 | xxx111    | xxx112    | 950      | 
| 111111111 | xxx111    | xxx145    | 750      |
| 111111111 | xxx112    | xxx145    | 250      |
I've trying some links, but I've no clue how to solve it, because I've been disconnected for a year from computer (COVID)
Links:
Calculating distance between two GPS locations in a data frame using distm () in R
Function to calculate geospatial distance between two points (lat,long) using R
Edit: Adding data
Sorry for my first writing. I was completely blocked and I was unable to ask in a proper way.
I've combine two dataframes (leftjoin) up to obtain the AAA_JOIN dataframe with "Doc_titular"
Now my problems starts:
1.-  Filter from "Doc_titular", and get al rows from a same "Doc_titular"
2.- Calculate distance between all LAT/LONG
3.- Store data in a CSV for each "Doc_titular" with all HouseID distances in mentioned format (Doc_titular; HouseId; HouseId(n); Meters)
Here's an example of the data:
Doc_titular House_ID    longitude   latitude
26DF5756F   AAA/BA/00145    -3.36715925514947   3.80089929185657
26DF5756F   AAA/BA/00146    -3.36687508416913   3.80092746460019
26DF5756F   AAA/BA/00733    -3.37604382639631   3.80126114282085
45GH7765B   AAA/BA/00123    -3.36887798896237   3.80405033823961
45GH7765B   AAA/BA/00498    -3.37077717656959   3.80121749925945
45GH7765B   AAA/BA/00998    -3.79037050320006   3.77633839304628
45GH7765B   AAA/BA/00332    -3.38064351196704   3.80099089206718
98TR2794P   AAA/BA/00420    -3.36824907065489   3.80086791973886
98TR2794P   AAA/BA/00557    -3.37255900917349   3.80107792023686
98TR2794P   AAA/BA/00556    -3.36674589155523   3.8012204114931
98TR2794P   AAA/BA/00040    -4.05181620512371   3.80137173136896
Sorry if i'm posting someting basic, but I'm not very good at R and I've been far far away for computer on this year. Thanks in advance.
 
    