as_date_ecotox {ECOTOXr} | R Documentation |
Values represented by ECOTOX character
to dates
Description
Similar to
as.Date()
, but it also
performs some text sanitising before coercing text to dates.
Usage
as_date_ecotox(x, dd = 1L, mm = 1L, nr = 1L, ..., warn = TRUE)
Arguments
x |
A vector of |
dd |
Replacement values for unspecified days in a date. Defaults to |
mm |
Replacement values for unspecified months in a date. Defaults to |
nr |
Replacement values for generically unspecified values in a date.
Defaults to |
... |
Passed to |
warn |
If set to |
Details
The following steps are performed (in the order as listed) to sanitise text before coercing it to numerics:
Trim whitespaces
Replace hyphens with forward slashes
Replace double forward slashes, forward slashes followed by a zero and spaces, with a single forward slash
Replace
"mm"
or"dd"
(case insensitive) with the value specified as argument. Add a forward slash to it when missing.Treat
"na"
,"nr"
,"xx"
and"00"
(case insensitive) as unreported values when followed by a forward slash. Replace it with thenr
argumentRemove alphabetical characters when directly followed by a numerical character.
Replace literal month names with its numerical calendar value (1-12).
When the date consists of one value, assume it is a calender year and add
dd
andmm
as day and month value.If a date consists of two numbers, assume it is month, followed by year. In that case insert the
dd
value for the day.
It is your own responsibility to check if the sanitising steps are appropriate for your analyses.
Value
A vector of Date
class objects with the same length as x
.
Author(s)
Pepijn de Vries
See Also
Other ecotox-sanitisers:
as_numeric_ecotox()
,
as_unit_ecotox()
,
mixed_to_single_unit()
,
process_ecotox_dates()
,
process_ecotox_numerics()
,
process_ecotox_units()
Examples
## a vector of commonly used notations in the database to represent
## dates. Most frequent format is %m/%d/%Y
char_date <- c("5-19-1987 ", "5/dd/2021", "3/19/yyyy", "1985", "mm/19/1999",
"October 2004", "nr/nr/2015")
as_date_ecotox(char_date)
## Set unspecified days to 15:
as_date_ecotox(char_date, dd = 15L)
## Unspecified days should result in NA:
as_date_ecotox(char_date, dd = -1L)
## Set unspecified months to 6:
as_date_ecotox(char_date, mm = 6L)
## Set generically unspecified value to 6:
as_date_ecotox(char_date, nr = 6L)