2

I have the data below and I want to convert from data_frame to sf object in R.

head(RwandanDataset[,8:13])

# A tibble: 6 x 6
  authority begin_datetime end_datetime longitude latitude elevation
  <chr>     <chr>          <chr>        <chr>     <chr>    <chr>    
1 WESTERN   01/01/2013     31/12/9999   29.42     -1.63    2392     
2 EASTERN   01/01/2013     31/12/9999   30.24     -1.55    1503     
3 EASTERN   01/01/2013     31/12/9999   30.51     -1.90    1575     
4 EASTERN   01/01/2013     31/12/9999   30.71     -2.01    1311     
5 EASTERN   01/01/2013     31/12/9999   30.67     -2.28    1576     
6 NORTHEN   01/01/2013     31/12/9999   30.06     -1.82    1865     

class(RwandanDataset)
[1] "tbl_df"     "tbl"        "data.frame"
zx8754
  • 52,746
  • 12
  • 114
  • 209
Jackline
  • 59
  • 1
  • 9
  • 6
    `sf::st_as_sf(RwandanDataset, coords = c("longitude", "latitude"), crs = 4326)` for xy coordinates. Beware that you need to make sure `longitude` and `latitude` are numeric, not character! In case you want xyz coordinates `sf::st_as_sf(RwandanDataset, coords = c("longitude", "latitude", "elevation"), crs = 4326)` should do. – TimSalabim Jul 24 '18 at 08:56
  • @TimSalabim This works perfectly. Thank you – Jackline Jul 24 '18 at 09:20

0 Answers0