Skip to contents

These functions resolve messydates by their central tendency. While the functions mean(), median(), and modal() summarise the vector to a single value, v*() versions return a vector of the same length.

Usage

# S3 method for class 'mdate'
median(..., na.rm = TRUE)

vmedian(..., na.rm = TRUE)

# S3 method for class 'mdate'
vmedian(..., na.rm = TRUE)

# S3 method for class 'mdate'
mean(..., trim = 0, na.rm = TRUE)

vmean(..., na.rm = TRUE)

# S3 method for class 'mdate'
vmean(..., trim = 0, na.rm = TRUE)

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

# S3 method for class 'mdate'
modal(..., na.rm = TRUE)

vmodal(..., na.rm = TRUE)

# S3 method for class 'mdate'
vmodal(..., na.rm = TRUE)

random(..., na.rm = TRUE)

# S3 method for class 'mdate'
random(..., na.rm = TRUE)

vrandom(..., na.rm = TRUE)

# S3 method for class 'mdate'
vrandom(..., na.rm = TRUE)

Arguments

...

a mdate 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.

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", "-0050-01-01"))
d
#>  'mdate' chr [1:9] "2008-03-25" "?2012-02-27" "2001-01?" "~2001" ...
median(d)
#> Warning: argument is not numeric or logical: returning NA
#> [1] NA
vmedian(d)
#> [1] "2008-03-25"  "2012-02-27"  "2001-01-16"  "2001-07-02"  "2001-01-17" 
#> [6] "2001-02-02"  "2001-01-17"  "2008-07-31"  "-0050-01-01"
mean(d)
#> [1] "1997-07-15"
vmean(d)
#> [1] "2008-03-25" "2012-02-27" "2001-01-16" "2001-07-02" "2001-01-17"
#> [6] "2001-01-17" "2001-01-16" "2008-07-15" "50-01-01"  
modal(d)
#> [1] "2001-01-01"
vmodal(d)
#> [1] "2008-03-25"  "2012-02-27"  "2001-01-01"  "2001-01-01"  "2001-01-01" 
#> [6] "2001-01-01"  "2001-01-01"  "2008-01-31"  "-0050-01-01"
random(d)
#> [1] "2001-01-09"
vrandom(d)
#> [1] "2008-03-25"  "2012-02-27"  "2001-01-05"  "2001-12-24"  "2001-01-31" 
#> [6] "2001-02-02"  "2001-01-06"  "2008-09-30"  "-0050-01-01"