Skip to content
R for the Rest of Us Logo

Fundamentals of R

Bring it All Together (Data Wrangling)

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.

View code shown in video
# Load Packages -----------------------------------------------------------

library(tidyverse)
library(janitor)

# Import Data -------------------------------------------------------------

# Data from https://github.com/rstudio/r-community-survey

survey_data <- read_tsv("2020-combined-survey-final.tsv") |> 
  clean_names()

survey_data |> 
  select(contains("enjoy"))

survey_data |> 
  filter(is.na(qr_enjoyment)) |> 
  select(qr_enjoyment)

survey_data |> 
  glimpse()

avg_r_enjoyment <- survey_data |> 
  drop_na(qr_enjoyment) |> 
  group_by(qcountry) |> 
  summarize(avg_enjoyment = mean(qr_enjoyment),
            n = n()) |> 
  filter(n >= 10) |> 
  arrange(desc(avg_enjoyment))

Learn More

If you want to see a visual representation of how the various dplyr functions you've learned in this section of the course work, check out the Tidy Data Tutor website.

A less visual, though equally useful, approach is the tidylog package. It gives you feedback on each step of your pipeline, showing the data was transformed.

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

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

Valliappan Muthu

Valliappan Muthu • May 17, 2024

Similar to select (var1:var2) is there a way to do drop_na (var1:var2)?

David Keyes

David Keyes Founder • May 17, 2024

I believe you can select a range in drop_na() though I've never actually tried it myself. Give it a shot and let me know if it works!

Valliappan Muthu

Valliappan Muthu • May 17, 2024

Hi. It works!

but the problem is I had one or more missing data in almost all observations, and I had zero observations after drop_na, Probably I need to recode NA to something else for a meaningful analysis.

David Keyes

David Keyes Founder • May 18, 2024

Yes, sounds more like an issue with your data at this point!