title: R doesn't like my coordinates - st_as_sf()
body: <p>Trying to convert a data frame to an sf object via this post (<a href="https://stackoverflow.com/questions/29736577/how-to-convert-data-frame-to-spatial-coordinates/45484314#45484314">How to Convert data frame to spatial coordinates</a>). However I keep getting the following error..
  <code>Error in `[.default`(x, coords) :  only 0's may be mixed with negative subscripts</code></p>
  <p>I tried to resolve it based off of this post (<a href="https://stackoverflow.com/questions/9221310/r-debugging-only-0s-may-be-mixed-with-negative-subscripts">R debugging: &quot;only 0&#39;s may be mixed with negative subscripts&quot;</a>), thinking because my coordinates were global, R didn't like the range of values. However I subset it to just a the north western hemisphere and recieved the same error. Below is the code I'm using</p>
  <pre><code>dat.sf &lt;- st_as_sf(x=dat2,
                     coords = c(dat2$centroid_lon, dat2$centroid_lat),
                     crs= &quot;+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0&quot;)
  </code></pre>
  <p>where dat2 is just the coordinates and a unique ID (group ID) for storm event associated with that lat and long.</p>
  <p>UPDATE: I tried a few other things, such as:</p>
  <pre><code>coordinates &lt;- as.data.frame(cbind(dat2$centroid_lon, dat2$centroid_lat))
  dat.sf &lt;- st_as_sf(x=dat2,
                     coords = coordinates,
                     crs= &quot;+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0&quot;)
  </code></pre>
  <p>and received this <code>Error in `[.default`(x, coords) : invalid subscript type 'list'</code></p>
  <p>and this....</p>
  <pre><code>coordinates &lt;- cbind(dat2$centroid_lon, dat2$centroid_lat)
  dat.sf &lt;- st_as_sf(x=dat2,
                     coords = coordinates,
                     crs= &quot;+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0&quot;)
  </code></pre>
  <p>and received this <code>Error in as.matrix(x)[i] : subscript out of bounds</code>. traceback() tells me it is definitely an issue with my coordinates.</p>