title: How to Convert data frame to spatial coordinates
body: <p>I have been working on earthquake data that has lat long values, and I want to convert those lat long values to spatial coordinates.</p>
  
  <p>Suppose I have the following data set <code>df</code>:</p>
  
  <pre><code>longitude          latitude
          128.6979    -7.4197
          153.0046    -4.7089
          104.3261    -6.7541
          124.9019    4.7817
          126.7328    2.1643
          153.2439    -5.6500
          142.8673    23.3882
          152.6890    -5.5710
  </code></pre>
  
  <p>I want to convert it into spatial points.
  Something like this:</p>
  
  <pre><code> lon        lat  
  [1,] 2579408.24 1079721.15
  [2,] 2579333.69 1079729.18
  [3,] 2579263.65 1079770.55
  [4,] 2579928.04 1080028.46
  [5,] 2579763.65 1079868.92
  [6,] 2579698.00 1079767.97
  </code></pre>
  
  <p>I used the following code:</p>
  
  <pre><code>library(sp)
  df.sp&lt;-df
  coordinates(df.sp)&lt;-~x+y
  </code></pre>
  
  <p>But I receive the following error:</p>
  
  <pre><code>Error in `[.data.frame`(object, , -coord.numbers, drop = FALSE) : 
    undefined columns selected
  </code></pre>