0

I have two different data frames:

46.70056    -69.71556   
48.70056    -70.71556       

And

46.70056    -69.71556   1010001 
49.70056    -71.71556   1010003 

I basically want to read the Latitude and Longitude in the first dataframe, match with the Lat-Long in the second dataframe, and if it matches, want to read the value from the third column and add it into the first dataframe. I could really use some help with the matching part. Earlier I was using the as.numeric(match(all$z,meta$y)). But that works with only one column. But since here I want to match two columns simultaneously, I am at a loss. Please help.

Geekuna Matata
  • 1,349
  • 5
  • 19
  • 38
  • Though a little higher level, another possible duplicate: [How to Join data frames in R](http://stackoverflow.com/a/1300618/903061). – Gregor Thomas Jun 09 '14 at 21:16
  • @josilber That's not my question. – Geekuna Matata Jun 09 '14 at 21:16
  • @GeekunaMatata if `merge` isn't the answer you want, then you've got a lot of work to do on your question. See `?merge`. – Gregor Thomas Jun 09 '14 at 21:17
  • Oh no. I misread the meaning of duplicate. Thought you meant that was my question and I was posting again. Checking the answer right now. – Geekuna Matata Jun 09 '14 at 21:18
  • Will this be the answer? total <- merge(dfA,dfB,by=c("lat","long")) – Geekuna Matata Jun 09 '14 at 21:20
  • ok, I used the command and it works! But just a slight problem. I don't want to add the extra rows that are in the dataframe I am matching to. Just want to add the values in the existing rows of first dataframe. How can I perform this exclusion? Right now, it matches everything and forms a super dataframe. – Geekuna Matata Jun 09 '14 at 21:26
  • Use `subset` on your super data.frame so you only get the columns you want. Or use one of the other methods (e.g., `dplyr` or `data.table`) in the link in my first comment. – Gregor Thomas Jun 09 '14 at 21:27
  • Could you help me a bit with that command? I haven't used that one before. – Geekuna Matata Jun 09 '14 at 21:29
  • @GeekunaMatata this site is for specific programming questions, not a step by step tutorial for stuff. – Señor O Jun 09 '14 at 21:29
  • @Gregor Thank you. Checking now. @ SeñorO Thank you. That was helpful. – Geekuna Matata Jun 09 '14 at 21:31

0 Answers0