This collection of S3 methods 'resolve' messy dates into a single date according to some explicit bias, such as returning the minimum or maximum date, the mean, median, or modal date, or a random date from among the possible resolutions for each messy date. If the date is not 'messy' (i.e. has no annotations) then just that precise date is returned. This can be useful for various descriptive or inferential projects.

# S3 method for messydt
min(..., na.rm = TRUE)

# S3 method for messydt
max(..., na.rm = TRUE)

# S3 method for messydt
median(..., na.rm = TRUE)

# S3 method for messydt
mean(..., trim = 0, na.rm = TRUE)

modal(..., na.rm = FALSE)

# S3 method for messydt
modal(..., na.rm = TRUE)

random(..., size, replace = FALSE, prob = NULL)

# S3 method for messydt
random(..., size, replace = FALSE, prob = NULL)

Arguments

...

a messydt object

na.rm

Should NAs be removed? True by default.

trim

the fraction (0 to 0.5) of observations to be trimmed from each end of x before the mean is computed. Values of trim outside that range are taken as the nearest endpoint.

size

a non-negative integer giving the number of items to choose.

replace

should sampling be with replacement?

prob

a vector of probability weights for obtaining the elements of the vector being sampled.

Value

A single scalar or vector of dates

Examples

d <- as_messydate(c("2008-03-25", "?2012-02-27", "2001-01?", "2001~",
"2001-01-01..2001-02-02", "{2001-01-01,2001-02-02}",
"{2001-01,2001-02-02}", "2008-XX-31"))
d
#>  'messydt' chr [1:8] "2008-03-25" "?2012-02-27" "2001-01?" "2001~" ...
min(d)
#> [1] "2008-03-25" "2012-02-27" "2001-01-01" "2001~"      "2001-01-01"
#> [6] "2001-01-01" "2001-01-01" "2008-01-31"
max(d)
#> [1] "2008-03-25" "2012-02-27" "2001-01-31" "2001~"      "2001-02-02"
#> [6] "2001-02-02" "2001-02-02" "2008-12-31"
mean(d)
#> [1] "2008-03-25" "2012-02-27" "2001-01-16" "2001~"      "2001-01-17"
#> [6] "2001-01-17" "2001-01-16" "2008-07-18"
median(d)
#> [1] "2008-03-25" "2012-02-27" "2001-01-16" "2001~"      "2001-01-17"
#> [6] "2001-02-02" "2001-01-17" "2008-07-31"
modal(d)
#> [1] "2008-03-25" "2012-02-27" "2001-01-01" "2001~"      "2001-01-01"
#> [6] "2001-01-01" "2001-01-01" "2008-01-31"
random(d)
#> [1] "2008-03-25" "2012-02-27" "2001-01-23" "2001~"      "2001-01-12"
#> [6] "2001-01-01" "2001-01-05" "2008-06-31"