Description Usage Arguments Details Value Author(s) Examples
View source: R/report.date.errors.R
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.
1 | report.date.errors(datevar)
|
datevar |
A vector containing dates |
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.
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. |
no.month |
index for all elements that consists of exactly 4 characters, i.e. |
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 |
Peter Konings
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)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.