A function for converting different types of dates into a numerical format.

dts(x, cent, sep, last)

Arguments

x

scalar, vector or list with dates to format

cent

use centuries? (optional and logical)

sep

separator, default " to " (only for cent)

last

take last input value in x? (optional and logical)

Details

When dating data has a character format like when involving AD, BC, BCE, C.E., etc., or even centuries like Cent., it is many times convenient to convert these type of dating data into a numerical format for a further computation.

In case that the input data has two or more plausible dates, then the outcome by default takes the first value of the input; otherwise the last date with option last.

dts also accepts dates involving centuries with the cent option. In this case, it is possible to specify a separator of the century endpoints in sep or use " to " as the default separator.

For dates having character format, then hyphens are regarded as separators of the plausible dates in x.

Value

Dating data with a numerical format.

Author

Antonio Rivero Ostoic

Note

Dating data with unknown year notations produce NA as output value.

See also

Examples

# negative first value
dts("58 BC - 30 AD")
#> 58 BC - 30 AD 
#>           -58 

# positive second value
dts("58 BC - 30 AD", last=TRUE)
#> 58 BC - 30 AD 
#>            30 

# use century notation
dts("15th Cent. AD", cent=TRUE)
#>  15th Cent. AD 
#> "1401 to 1500"