title: Extract data using a matching matrix pair of data in R
body: <p>I have two data sets with latitude, longitude, and temperature data. One data set corresponds to a geographic region of interest with the corresponding lat/long pairs that form the boundary and contents of the region (Matrix Dimension = 4518x2)</p>
  
  <p>The other data set contains lat/long and temperature data for a larger region that envelopes the region of interest (Matrix Dimenion = 10875x3).</p>
  
  <p>My question is: How do you extract the appropriate row data (lat, long, temperature) from the 2nd data set that matches the first data set's lat/long data?</p>
  
  <p>I've tried a variety of "for loops," "subset," and "unique" commands but I can't obtain the matching temperature data.</p>
  
  <p>Thanks in advance!</p>
  
  <hr>
  
  <p>10/31 Edit: I forgot to mention that I'm using "R" to process this data.</p>
  
  <p>The lat/long data for the region of interest was provided as a list of 4,518 files containing the lat/long coordinates in the name of each file:</p>
  
  <pre><code>x&lt;- dir()
  
  lenx&lt;- length(x)
  
  g &lt;- strsplit(x, "_")
  
  coord1 &lt;- matrix(NA,nrow=lenx, ncol=1)  
  coord2 &lt;- matrix(NA,nrow=lenx, ncol=1)
  
  for(i in 1:lenx) {  
  coord1[i,1] &lt;- unlist(g)[2+3*(i-1)]  
  coord2[i,1] &lt;- unlist(g)[3+3*(i-1)]     
  } 
  
  coord1&lt;-as.numeric(coord1)  
  coord2&lt;-as.numeric(coord2)
  
  coord&lt;- cbind(coord1, coord2)
  </code></pre>
  
  <p>The lat/long and temperature data was obtained from an NCDF file for with temperature data for 10,875 lat/long pairs:</p>
  
  <pre><code>long&lt;- tempcd$var[["Temp"]]$size[1]   
  lat&lt;- tempcd$var[["Temp"]]$size[2]   
  time&lt;- tempcd$var[["Temp"]]$size[3]  
  proj&lt;- tempcd$var[["Temp"]]$size[4]  
  
  temp&lt;- matrix(NA, nrow=lat*long, ncol = time)  
  lat_c&lt;- matrix(NA, nrow=lat*long, ncol=1)  
  long_c&lt;- matrix(NA, nrow=lat*long, ncol =1)  
  
  counter&lt;- 1  
  
  for(i in 1:lat){  
      for(j in 1:long){  
          temp[counter,]&lt;-get.var.ncdf(precipcd, varid= "Prcp", count = c(1,1,time,1), start=c(j,i,1,1))  
          counter&lt;- counter+1  
      }  
  }  
  
  temp_gcm &lt;- cbind(lat_c, long_c, temp)`
  </code></pre>
  
  <p>So now the question is how do you remove values from "temp_gcm" that correspond to lat/long data pairs from "coord?"</p>