Counting Part 1
As a JedR Padawan of the Galactic News Hub, you have been assigned to help with a new story about the demographics of the Star Wars Universe. After pitching a few different topics, your droid editor (J-327D) has green lighted a pitch about species variation. For this article, you have been asked to provide a summary statistic about which species is the most common in the Star Wars universe.
For this task, you will summarize and group the characters by species. You will then arrange the data to identify the most common species of all the Star Wars characters.
Summarize and count
If you recall from our earlier exercise, starwars
is a dataset with 87 Star Wars characters.
First, we’ll need to group the data by species and then summarize by counting the number of rows of each species. (We will tackle the arranging part later.)
J-327D is a bit insistent that you spell it summarize and not summarise.
How do we do that? What functions would we use? We insist you name the new variable “characters”!
starwars |>
group_by(species) |>
summarize(characters = n())
|>
starwars group_by(species) |>
summarize(characters = n())
Your editor J-327D says that the tidyverse function summarize()
and the n()
function are super useful to count rows of data. He says it’s “even cooler” if you use group_by()
.
JedR challenge
J-327D says that Jar Jar Binks is his favorite being in the Unvierse.
How many Gungan characters are there?
There are three Gungan characters in the starwars
data.
You’ve got the strength of a thousand stormtroopers (but with way better aim)!
Once you’ve completed the exercises above, move to the next part of this trial.