Get access to all lessons in this course.
Going Deeper with R
Advanced Data Wrangling and Analysis
- Importing Data
- Tidy Data
- Reshaping Data
- Dealing with Missing Data
- Changing Variable Types
- Advanced Variable Creation
- Advanced Summarizing
- Binding Data Frames
- Merging Data
- Renaming Variables
- Quick Interlude to Reorganize our Code
- Exporting Data
Advanced Data Visualization
- Data Visualization Best Practices
- Tidy Data
- Pipe Data Into ggplot
- Reorder Plots to Highlight Findings
- Line Charts
- Use Color to Highlight Findings
- Use the scales Package for Nicely Formatted Values
- Use Direct Labeling
- Use Axis Text Wisely
- Use Titles to Highlight Findings
- Use Color in Titles to Highlight Findings
- Use Annotations to Explain
- Tweak Spacing
- Customize Your Theme
- Customize Your Fonts
- Try New Plot Types
- Advanced Markdown Text Formatting
- Advanced YAML
- Inline R Code
- Making Your Reports Shine: Word Edition
- Making Your Reports Shine: HTML Edition
- Making Your Reports Shine: PDF Edition
- Other Formats
- You Did It!
This lesson is locked
This lesson is called Tables, part of the Going Deeper with R course. This lesson is called Tables, part of the Going Deeper with R course.
Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.
enrollment_by_race_ethnicity %>% filter(race_ethnicity == "Hispanic/Latino") %>% pivot_wider(id_cols = c(district, district_id), names_from = year, values_from = percent_of_total_at_school) %>% mutate(growth = `2018-2019` - `2017-2018`) %>% arrange(desc(growth)) %>% select(-district_id) %>% slice_max(growth, n = 10) %>% gt() %>% cols_label( district = "District", growth = "Growth" ) %>% fmt_percent( columns = vars(`2017-2018`, `2018-2019`, growth), decimals = 1 )
Change the default data frame printing method to use kable
Choose one of the table packages and make an attractive table that shows the top 10 districts with the highest percentage of Hispanic/Latino students (hint: use the
slice_max()function to get the top 10 and the
fmt_percent()function if you’re using
percent()function otherwise to display the percentage of Hispanic/Latino students in each)
Please note that in order to use the
slice_max() function, you need to have
dplyr 1.0 or greater installed.
If you want to read more about df_print options, you can find that here.
If you’re looking for an overview of all of the table packages discussed in this lesson, check out this comprehensive blog post I wrote.
That blog post includes links to some great tutorials on the various packages. Some additional tutorials have come out since then, especially on the
gt package. See, for example, tutorials by:
In case it’s not already clear, the
gt package is really popular, in large part because of this endorsement from Hadley Wickham.