Useful R codes

How to get min and max value and the associated year that min and max values occurred

previous <- dfile %>%
filter(YearLabel == “Previous”) %>%
group_by(MonthName) %>%
summarize(
min_extent = min(extent_mil),
max_extent = max(extent_mil),
year_min = Year[which.min(extent_mil)],
year_max = Year[which.max(extent_mil)]
)