# >
Mutating columns
For these exercises, we’ll use the dog breed traits data set, so import that from https://jeffreyrstevens.quarto.pub/dpavir/data/dog_breed_traits.csv (if you don’t already have it) and assign it to traits
.
- View
traits
to see what it looks like.
# >
- Reassign
traits
with only the columns Breed through Coat Length.
# >
- Reassign
traits
removing the Drooling Level column. That’s gross.
# >
- What terrible column names! Reassign
traits
and change the column names to"breed", "affectionate", "children", "other_dogs", "shedding", "grooming", "coat_type", "coat_length"
. Note, use thecolnames()
function rather thanselect()
orrename()
since you already have the full vector of names.
# >
- The ratings are supposed to run from 0 to 4 rather than 1 to 5. Change the affectionate column by subtracting 1 from the original numbers to rescale the values. Don’t reassign
traits
.
# >
- Actually, all of the ratings need to be rescaled. Subtract 1 from all of the ratings columns by using
across()
.
# >
- Create a new column called coat that combines the coat_type and coat_length columns by pasting the values of those two columns separated by
-
.
# >
- Create a new column called shed that dichotomizes shedding such that values of 3 and above are “A lot” and values below 3 are “Not much”. Do you need to account for missing data?
# >
- Use
rowwise()
to calculate the mean rating for the children and other_dogs columns in a column calledmean_rating
.
# >
- Create a column called coat_type2 that categorizes the coat_type values in the following way and puts it after coat_type:
- “very petable” = “Smooth”, “Silky”, “Wavy”
- “petable” = “Double”, “Curly”
- “not petable” = “Wiry”, “Hairless”, “Rough”, “Corded”
# >