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.

flow

temp

Please install and load `lubridate, imputeTS, hydroTSM, hydroGOF`

package before starting the exercise

**Exercise 1**

Load data and tidying it up including delete unnecessary column, converting time to `POSIXct`

class

**Exercise 2**

create a `spline`

function (essentially the equation for a curve plotted through the observed temperature)

**Exercise 3**

evaluate `tempSpline`

at times where we have observed flow to give approximate temperature for each of these points

**Exercise 4**

creating a new 15-minute data frame containing both the temperature and flow

**Exercise 5**

plot temperature and set axis ticks to weekly intervals with date stamps every two weeks

**Exercise 6**

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

**Exercise 7**

Load new dataset for analysing missing value

flow

**Exercise 8**

Check `NA`

value composition and fill the missing values using `imputation`

**Exercise 9**

using `na.interpolation `

for imputation; use three method including interpolation,Kalman and mean method

**Exercise 10**

Join date and time, the original and prediction value into one data frame

**Exercise 11**

use `ggof`

function to plot the original and prediction value

**What's next:**

- 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

## Leave a Reply