Get access to all lessons in this course.
- Welcome to Fundamentals of R
- Update Everything
- Start a New Project
-
Data Wrangling and Analysis
- The Tidyverse
- Pipes
- select()
- mutate()
- filter()
- summarize()
- group_by() and summarize()
- arrange()
- Create a New Data Frame
- Bring it All Together (Data Wrangling)
-
Data Visualization
- The Grammar of Graphics
- Scatterplots
- Histograms
- Bar Charts
- Setting color and fill Aesthetic Properties
- Setting color and fill Scales
- Setting x and y Scales
- Adding Text to Plots
- Plot Labels
- Themes
- Facets
- Save Plots
- Bring it All Together (Data Visualization)
-
Quarto
- Quarto Overview
- YAML
- Text
- Code Chunks
- Tips for Working with Quarto
- Bring It All Together (Quarto)
-
Wrapping Up
- An Important Workflow Tip
Fundamentals of R
Crosstabs
This lesson is locked
This lesson is called Crosstabs, part of the Fundamentals of R course. This lesson is called Crosstabs, part of the Fundamentals of R 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
Complete the crosstabs sections of the data-wrangling-and-analysis-exercises.Rmd file. Make sure that you have the janitor package installed (if not, use the install.packages function) and loaded (use the library function).
Learn More
The janitor package has a great vignette with information about the tabyl and adorn_ functions.
You need to be signed-in to comment on this post. Login.
Daniel Sossa
March 14, 2021
I noticed that the rendered table you get when knitting after adding a third variable is not the same you get when doing only two (it is only text, not the nice table format). Is there a way to get the same type of table rendered?
David Keyes
March 16, 2021
Alright, so this is not my strongest area, but I tried to explain this a bit in this video. Hope it helps!
Vuk Sekicki
March 29, 2021
This video does not have sound. Tnx
David Keyes
March 29, 2021
Oops, sorry! I'll re-record later today.
David Keyes
March 30, 2021
Ok, the video linked now from the comment above is updated. Hope it helps!
Abby Isaacson
March 31, 2021
I had this same question, thanks for addressing it (even though it makes me want to avoid that for now!).
Jyoni Shuler
March 26, 2021
To solve the error message and remove the N/As, would we use the 'drop_na' function then?
David Keyes
March 29, 2021
Yup, that works! You can run that before doing the crosstab, which will get rid of any missing values and thus should get rid of the error message.
Tatiana Bustos
July 28, 2022
For the last coding solution - what do the $ indicate next to the age_decade? Will this show up in the table in the final report (once we convert to word or other)? Is there a way to remove that and just show the actual age_decade labels?
David Keyes
July 29, 2022
I'm not sure exactly why there is a $, but it will show up in your Word document when you knit. To be honest, I don't use the
tabyl()
functions for final outputs that I would share with others, just for exploring the data on my own when starting out. As a result, I don't care that much about having the ugly $.Emma S
October 6, 2022
Is there a way to show both column & row percentages using tabyl? Or is there another crosstab function that could do this? (I'm thinking similar to a proc freq in SAS, which has frequency, percent, column percent and row percent for each cell)
David Keyes
October 6, 2022
I believe the adorn_percentages() function should do this, unless I'm missing something about your question.
Emma S
October 6, 2022
Hi David! I figured it out, I just had to mess with the denominator to get what I was looking for: adorn_percentages(denominator = "col")
Thanks!
David Keyes
October 6, 2022
Great!