Applications
- Replace
NA
values with values from cubic interpolation - (Exercise 5-23)
euraud <- scan("https://raw.githubusercontent.com/gagolews/teaching-data/master/marek/euraud-20200101-20200630.csv", comment.char = "#")
# create index of NA values
na_index <- is.na(euraud) == TRUE
# assign interpolated values from spline()
# to the NA values using the index
euraud[na_index] <- spline(euraud, n = length(euraud)) |>
_[["x"]] |> # spline() returns a named list
_[na_index]