ComenzarEmpieza gratis

Replace missing data - II

Like most aspects of time series data manipulation, there are many ways to handle missingness. As you discovered in the previous exercise, both the locf and nocb approach require you to make certain assumptions about growth patterns in your data. While locf is more conservative and nocb is a more aggressive, both generate step-wise growth from missing data.

But what if you have reason to expect linear growth in your data? In this case, it may be more useful to use linear interpolation, which generates new values between the data on either end of the missing value weighted according to time.

In this exercise, you'll fill the missing values in your gdp_xts data using the na.approx() command, which uses interpolation to estimate linear values in time.

Este ejercicio forma parte del curso

Case Study: Analyzing City Time Series Data in R

Ver curso

Instrucciones del ejercicio

  • Use na.approx() to fill the missing values in gdp_xts using linear interpolation. Save this new xts object as gdp_approx.
  • Plot your new xts object using plot.xts().
  • Query your new xts object for GDP in 1993.

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

# Fill NAs in gdp_xts using linear approximation
gdp_approx <- 

# Plot your new xts object
plot.xts(___, major.format = "%Y")
  
# Query for GDP in 1993 in gdp_approx
Editar y ejecutar código