Skip to content
Join our email list to get $80 off Ally in November →
R for the Rest of Us Logo

Going Deeper with R

Tidy Data Rule #2: Every Row is an Observation

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

Run the following code to view the built-in gss_cat data frame.

library(tidyverse)

gss_cat |>
  view()

Then, write code to count the number of unique responses in the partyid variable.

You’ll need to use the separate_longer_delim() and count() functions to do this.

Learn More

This lesson from the R for Social Scientists course materials covers separate_longer_delim().

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

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

Mallik Janthak

Mallik Janthak • November 1, 2026

In gss_cats, partyid is shown to be of the type <fct>. Can you refresh my memory on this type and where it is used?

Gracielle Higino

Gracielle Higino Coach • November 3, 2026

Hi Mallik! Factors are categorical variables that can be ordered by a defined order other than alphabetical or numerical. We have a special lesson about this here. We use factors pretty much everytime we need a categorical variable that has an intrinsic order of values (like "big", "medium" and "small"), instead of a character variable (you can think of those as plain text variables that are not ordered, like species names). I hope this helps! We'll have a moment to discuss that in the live session this week.

Lilly Yu

Lilly Yu • November 5, 2026

I noticed that in the solution, there is a select(partyid) |>, whereas the code I modeled mine off in the video omitted this. I got the same result using both code. What does select(partidyid) do here exactly?

Gracielle Higino

Gracielle Higino Coach • November 5, 2026

Hi Lilly! You can get the same result without the select() in this case. It's here for clarity and pedagogical purposes only, just so we focus on this variable specifically. As always, there are many ways to do the same thing in R!

Course Content

44 Lessons

New from Ally Translate between base R and the tidyverse