Skip to content
New course: Interactive Dashboards with Shiny. Get 50% off with coupon SHINYLAUNCH.
R for the Rest of Us Logo

Mapping with R

34 lessons

Turning Data Frames into sf Objects (01_05)

This lesson is locked

Get access to all lessons in this course.

Transcript

Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.

Your Turn

Open the 01_05.Rproj file to open the appropriate project.

Open the airport-locations.R file from the worked-examples/01_05 folder.

Visualise the locations of the airports in the airports-with-most-seat-kilometers_2015.xlsx file

  • Import the file with read_excel()

  • Use st_as_sf() to convert the tibble into an sf object

  • Use mapview to show the airport locations

Learn More

In this video I used the tribble() function for creating a dataset in R code. It’s convenient to use this function instead of data.frame() as it allows us to create datasets by row instead of by column.

tribble() also creates a tibble instead of a data.frame. The tidyverse introduced the tibble as a modern version of the data.frame, it looks prettier in the console and it allows functions like group_by() to work. If you want a more technical description check out the package website.

Have any questions? Put them below and we will help you out!

You need to be signed-in to comment on this post. Login.

Haresh Suppiah

Haresh Suppiah

March 1, 2022

Hi,

I just wanted to point out a couple of things. It seems like the github solution on this page is not synced with the solution used in the video. Also, the file name for the student exercise should be 'your-turn.R' instead of 'airport-locations.R'.

These edits might help others. Cheers,

David Keyes

David Keyes

March 2, 2022

Thanks for the heads up! I've fixed both things.