Split the coat column into type and length and keep the original coat column.
traits2 |>separate(coat, into =c("type", "length"), remove =FALSE)
# A tibble: 197 × 9
breed affectionate children other_dogs shedding grooming coat type length
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr>
1 Retrie… 5 5 5 4 2 Doub… Doub… Short
2 French… 5 5 4 3 1 Smoo… Smoo… Short
3 German… 5 5 3 4 2 Doub… Doub… Medium
4 Retrie… 5 5 5 4 2 Doub… Doub… Medium
5 Bulldo… 4 3 3 3 3 Smoo… Smoo… Short
6 Poodles 5 5 3 1 4 Curl… Curly Long
7 Beagles 3 5 5 3 2 Smoo… Smoo… Short
8 Rottwe… 5 3 3 3 1 Smoo… Smoo… Short
9 Pointe… 5 5 4 3 2 Smoo… Smoo… Short
10 Dachsh… 5 3 4 2 2 Smoo… Smoo… Short
# ℹ 187 more rows
Create traits3 from traits that (1) removes the coat columns, (2) turns the ratings columns into long format, and (3) removes the children row for Bulldogs.
Create traits4 from traits3 that ensures a complete data set with all five ratings for all breeds (and fills in missing combinations with NA) and check for the missing Bulldog children row.
traits4 <- traits3 |>complete(breed, scale)
How could we copy the rating from the previous row into the Bulldog children row to replace the NA? (Note this is not a good idea in this case!)
# A tibble: 18 × 2
coat_type coat_length
<chr> <chr>
1 Corded Long
2 Corded Medium
3 Curly Long
4 Curly Medium
5 Double Long
6 Double Medium
7 Double Short
8 Hairless Short
9 Rough Long
10 Rough Medium
11 Silky Long
12 Silky Medium
13 Smooth Medium
14 Smooth Short
15 Wavy Long
16 Wavy Medium
17 Wiry Medium
18 Wiry Short
From traits, generate all possible combinations of coat type and length, excluding NA.
# A tibble: 27 × 2
coat_type coat_length
<chr> <chr>
1 Corded Long
2 Corded Medium
3 Corded Short
4 Curly Long
5 Curly Medium
6 Curly Short
7 Double Long
8 Double Medium
9 Double Short
10 Hairless Long
# ℹ 17 more rows