How to check missing days in datasets in R

It is better to ask one question per thread.
For your problem with loading the xlsx package, the error mentions that the rJava package is missing. What happens if you run

install.packages("rJava")

For changing the name of the fourth column in your data frame and finding the missing dates, please see the code below.

DF <- data.frame(Year = rep(1985, 4), 
                 Month = rep(1, 4), 
                 Day = c(1,2,5,6), 
                 Z = 7:10)
DF
#>   Year Month Day  Z
#> 1 1985     1   1  7
#> 2 1985     1   2  8
#> 3 1985     1   5  9
#> 4 1985     1   6 10
colnames(DF)[4] <- "Data"
DF
#>   Year Month Day Data
#> 1 1985     1   1    7
#> 2 1985     1   2    8
#> 3 1985     1   5    9
#> 4 1985     1   6   10
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#> 
#>     date
DF$DATE <- make_date(year = DF$Year, month = DF$Month, day = DF$Day)
DF
#>   Year Month Day Data       DATE
#> 1 1985     1   1    7 1985-01-01
#> 2 1985     1   2    8 1985-01-02
#> 3 1985     1   5    9 1985-01-05
#> 4 1985     1   6   10 1985-01-06
FullSeq <- seq.Date(from = min(DF$DATE), to = max(DF$DATE), by = 1)
Missing <- FullSeq[!FullSeq %in% DF$DATE]
Missing
#> [1] "1985-01-03" "1985-01-04"

Created on 2019-11-23 by the reprex package (v0.3.0.9000)

1 Like