Robust data is a key for robust result in hydrological analysis. Problems that often happen with time series data analysis are missing value and different time scale measurement. Those two problems can be solved by doing spatial/temporal interpolation and or/ spatial modelling.
In this exercise, we will discuss how to resample time series dataset with
NA value and different time scale measurement. We will use two datasets with different time scale measurement. Flow observations were measured in 30 minutes interval while river temperature in 15 minutes interval.
The most common used method is cubic spline. A cubic spline essentially fits a curve through a set of data points, and then allows you to then specify the locations along the curve for which you would like to generate data.
Answers to the exercises are available here. If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.
Dataset is generated from previous exercise.
Please install and load
lubridate, imputeTS, hydroTSM, hydroGOF package before starting the exercise
Load data and tidying it up including delete unnecessary column, converting time to
spline function (essentially the equation for a curve plotted through the observed temperature)
tempSpline at times where we have observed flow to give approximate temperature for each of these points
creating a new 15-minute data frame containing both the temperature and flow
plot temperature and set axis ticks to weekly intervals with date stamps every two weeks
plot the discharge on a secondary axis. Here, we use the
par command to tell R to use the same window for the new plot and draw legend
Load new dataset for analysing missing value
NA value composition and fill the missing values using
na.interpolation for imputation; use three method including interpolation,Kalman and mean method
Join date and time, the original and prediction value into one data frame
ggof function to plot the original and prediction value
- Become a Top R Programmer Fast with our Individual Coaching Program
- Explore all our (>4000) R exercises
- Find an R course using our R Course Finder directory
- Subscribe to receive weekly updates and bonus sets by email
- Share with your friends and colleagues using the buttons below