title: Incorrect number of dimensions when using geosphere package in R
body: <p>Trying to calculate the distance matrix between lat/long points in  two datasets.... 
  This is my R script code and then the error message. Any ideas on where I am going wrong?</p>
  
  <pre><code>&gt; library(geosphere)
  ## step 1: open 2000 data for birds and air temp
  &gt; birds&lt;-read.table(file.choose(),header=T,sep="\t")
  &gt; birds
  &gt; temp&lt;-read.table(file.choose(),header=T,sep="\t")
  &gt; temp
  
  ##step 2: calculate the distance matrix D, which is the distance between lat/long points in your two datasets
  
  &gt; D = distm (birds&lt;- 3:2, temp&lt;- 2:1)
  &gt; new_birds =cbind(birds, temp[apply(D , 1 , which.min),])
  </code></pre>
  
  <blockquote>
    <p>Error in temp[apply(D, 1, which.min), ] : incorrect number of
    dimensions</p>
  </blockquote>