Automatically filling in missing data

The zoo package has several methods for automatically filling in missing time-series data.

  a <- matrix(as.numeric(as.matrix(sweden[, 5:52])), nrow = 48, byrow = T)
  a <- zooreg(a, frequency = 12, start = 2005)
  ## replacing each ‘NA’ with the most recent non-‘NA’ prior to it.
  a <- na.locf(a, na.rm = F)
  a <- na.locf(a, na.rm = F, fromLast = T)
  ## turn the data part of a into factors again
  coredata(a) <- matrix(factor(coredata(a)), nrow = 48, ncol = 1929)

comments powered by Disqus


Back to the index

Blog roll

R-bloggers, Debian Weekly
Valid XHTML 1.0 Strict [Valid RSS] Valid CSS! Emacs Muse Last modified: oktober 17, 2019