report.date.errors: Report common date errors

Description Usage Arguments Details Value Author(s) Examples

View source: R/report.date.errors.R

Description

This function takes a vector containing dates and tries to convert it to POSIX-ct format. It reports a number of errors that commonly occur in the Swedish registries.

Usage

1

Arguments

datevar

A vector containing dates

Details

datevar will usually be a factor, character or numeric after importing a dataset. First, it is converted to character, then to POSIX-ct. A list is returned with the index of common failures.

Value

A list with the following components:

wrong.format

index for all elements that consist of exactly 8 characters

no.day

index for all elements that consist of exactly 6 characters, i.e. yyyymm

no.month

index for all elements that consists of exactly 4 characters, i.e. yyyy

empty

index for all empty and missing elements

not.parsable

index for all elements with errors

wrong.date

index for elements that are not parsable, but are not empty either

Author(s)

Peter Konings

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (datevar) 
{
    datevar.char <- as.character(datevar)
    wrong.format <- which(nchar(datevar.char) != 8)
    no.day <- which(nchar(datevar.char) == 6)
    no.month <- which(nchar(datevar.char) == 4)
    empty <- which(is.na(datevar.char) | datevar.char == "")
    datevar.date <- ymd(datevar.char)
    not.parsable <- which(is.na(datevar.date))
    wrong.date <- setdiff(not.parsable, union(empty, union(no.day, 
        no.month)))
    result <- list(wrong.format = wrong.format, no.day = no.day, 
        no.month = no.month, empty = empty, not.parsable = not.parsable, 
        wrong.date = wrong.date)
    return(result)
  }

lemna/ugir documentation built on May 21, 2019, 3:07 a.m.