# >
Merging rows
For these exercises, we’ll use the dog breed traits and dog breed popularity rankings data sets.
- Load tidyverse, import
dog_breed_traits_clean.csv
totraits
, importdog_breed_ranks.csv
toranks
, and importdog_breed_ranks.csv
topopularity
.
- First, set a random seed by using
set.seed(2)
. Then create a subset ofranks
that is a random selection of 10% of the rows, sort by breed name, and assign toranks2
.
# >
- Use a filtering join to return the subset of
traits
that matches the breeds inranks2
and assign this totraits2
.
# >
- Use a filtering join to return the subset of
traits
that excludes the breeds inranks2
.
# >
- Now we want to filter
traits
based on breeds inpopularity
. Notice that the breeds column inpopularity
is called Breed. This is problematic because the breed column intraits
is called breed and names are case-sensitive. Usejoin_by()
to filtertraits
by breeds inpopularity
. How many rows are there?
# >
- Use
filter()
(not joins) to return the subset oftraits
that excludes the breeds inranks2
.
# >
- Append
traits2
to the bottom of itself.
# >
- Append
traits2
to the right of itself.
# >
- Append
traits2
to the right ofranks2
.
# >
- Why is this not a good idea? What would be a better way to achieve this?
# >