Using the dplyr lag and lead function to find the length of drought (CC245)
Channel: Riffomonas Project
Date: 2022-09-06

The lag and lead functions from dplyr allow you to create columns that are offset from the reference column by one or more rows. In this Code Club, Pat responds to a commenter's question to calculate the number of days between precipitation events to see if the length of drought is increasing or decreasing over time. Pat will address these questions using local weather data downloaded from NOAA in RStudio with a lot of help from the tidyverse and the bench R package

You can find my blog post for this episode at https://www.riffomonas.org/code_club/2022-09-06-lag-lead.

#lag #lead #dplyr #tidyverse #R #Rstudio #Rstats

Support Riffomonas by becoming a Patreon member!
https://www.patreon.com/riffomonas

Want more practice on the concepts covered in Code Club? You can sign up for my weekly newsletter at https://shop.riffomonas.org/youtube to get practice problems, tips, and insights.

If you're interested in taking an upcoming 3 day R workshop be sure to check out our schedule at https://riffomonas.org/workshops/

You can also find complete tutorials for learning R with the tidyverse using...
Microbial ecology data: https://www.riffomonas.org/minimalR/
General data: https://www.riffomonas.org/generalR/

0:00 Introduction
1:37 Plan for attacking problem
3:19 Replacing NA values with 0
4:50 Filtering out no or low precipitation days
6:07 Lag vs. lead
8:05 Calculating the length of drought
9:38 Visualizing the length of drought for one year
11:28 Calculating and visualizing summary statistics
17:08 Cleaning up appearance of visualization