Aha Moments while doing data wrangling in Tidyverse Ecosystem
Priyanka Gagneja
Data Analytics Consultant @ OnPoint Insights
Data Analytics Freelancer
Twitter: priyankaigit
Linkedin: priyanka-gagneja
select()
filter()
arrange()
mutate()
summarise()
group_by()
Important
Details in the documentation !!
food <- tibble(
food = c('Banana', 'Apple', 'Lemon','Potato', 'Tomato', 'Mango', 'Carrot'),
type = c('fruit','fruit','vegetable','vegetable','vegetable','fruit','vegetable'),
px_2000_usd = c(5, 10, 5, 8, 3, 9, 12),
px_2010_usd = c(7, 9, 7, 8, 5, 10, 13),
px_2020_usd = c(8, 9, 8, 10, 6, 13, 14)
) %>%
mutate(type = factor(type, levels = c('fruit', 'vegetable','staple')))
food %>%
gt()| food | type | px_2000_usd | px_2010_usd | px_2020_usd |
|---|---|---|---|---|
| Banana | fruit | 5 | 7 | 8 |
| Apple | fruit | 10 | 9 | 9 |
| Lemon | vegetable | 5 | 7 | 8 |
| Potato | vegetable | 8 | 8 | 10 |
| Tomato | vegetable | 3 | 5 | 6 |
| Mango | fruit | 9 | 10 | 13 |
| Carrot | vegetable | 12 | 13 | 14 |
_if , _at variants
Use fill option if you would like to replace NA to another value like 0 or 9999.
To keep groups with zero length in output
| food | type | food_upper | px_2000_usd | px_2010_usd | px_2020_usd |
|---|---|---|---|---|---|
| Banana | fruit | BANANA | 5 | 7 | 8 |
| Apple | fruit | APPLE | 10 | 9 | 9 |
| Lemon | vegetable | LEMON | 5 | 7 | 8 |
| Potato | vegetable | POTATO | 8 | 8 | 10 |
| Tomato | vegetable | TOMATO | 3 | 5 | 6 |
| Mango | fruit | MANGO | 9 | 10 | 13 |
| Carrot | vegetable | CARROT | 12 | 13 | 14 |