Handling missing values¶
The following makes use of the zoo package. You may need to install it from
CRAN using the code
install.packages("zoo")
if you want to run this on your computer. (The
package is already installed on the notebook container, however.)
library(zoo)
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
The file “zpresidents.RData” was created in an earlier example.
load("zpresidents.RData")
# Leads to an error:
presidents.o <- na.omit(presidents)
Error in na.omit.ts(presidents):
time series contains internal NAs
zpresidents.o <- na.omit(zpresidents)
c("Original length" = length(zpresidents),
"Length after dropping NAs" = length(zpresidents.o))
Original length Length after dropping NAs
120 114
- R file: handling-missing-values.R
- Rmarkdown file: handling-missing-values.Rmd
- Jupyter notebook file: handling-missing-values.ipynb
- Interactive version of the Jupyter notebook (shuts down after 60s):
- Interactive version of the Jupyter notebook (sign in required):