title: Reprojecting & CRS of Shapefile using sf Package in R
body: <p>I am a new R user. I have a shapfile in R which I want to use to calculate the K nearest neighbor. Each polygon's centroid (Inside_X &amp; Inside_Y) was calculated in arcmap (Example: X: 32570914 Y: 5791442). I used the <code>sf</code> package to get a CRS for my coordinates. Ideally, I would like to use the proj of my shapefile but it seems invalid in R. Below is my code. My problem is that the <code>knearneighbor</code> considers <code>knearneigh: coordinates are not geographical</code> and <code>st_is_longlat</code> gives<code>[FALSE]</code> even after setting a CRS. Please help.</p>
  
  <pre><code>&gt;data&lt;- readOGR (dsn = ".", layer ="My_Data")
  &gt;summary(data)
  
      Object of class SpatialPolygonsDataFrame
      Coordinates:
             min      max
      x 32568756 32641426
      y  5723944  5853056
      Is projected: TRUE 
      proj4string :
      [+proj=tmerc +lat_0=0 +lon_0=9 +k=0.9996 +x_0=32500000 +y_0=0 +ellps=GRS80 +units=m +no_defs]
      Data attributes:
  
  
  &gt;data.sf &lt;- st_as_sf(data)
  
  
  ## Set CRS
  &gt;data.crs &lt;- st_transform(data.sf, crs = 4839)
  &gt;st_crs(data.crs)
  
  data.coord &lt;- cbind(data.crs$INSIDE_X, data.crs$INSIDE_Y)
  
  ## K Nearest neighbor
  &gt;library(spdep)
  &gt;data.knn &lt;- knearneigh(data.coord, k = 10, longlat = TRUE)
  
  Warning message:
  In knearneigh(data.coord, k = 10, longlat = TRUE) :
    knearneigh: coordinates are not geographical: longlat argument wrong
  </code></pre>