Import data
# excel file
beesdata <- read_excel("../03_module6/beesdata.xlsx")
beesdata
Apply the following dplyr verbs to your data
Filter rows
filter(beesdata, year == 2013, state == "New Hampshire")
Arrange rows
arrange(beesdata, desc(colony_lost_pct), desc(year))
Select columns
select(beesdata, year, months, state, colony_lost)
select(beesdata, year, months, state, contains("pct"))
Add columns
mutate(beesdata,
colony_after_loss = colony_n - colony_lost) %>%
select(year, state, colony_after_loss)
Summarize by groups
beesdata %>%
group_by(state) %>%
summarise(avg_loss = mean(colony_lost_pct, na.rm = TRUE)) %>%
arrange(avg_loss)