在 R 编程中找出两个日期之间的差异 – julian()函数
在 R 编程中,可以通过使用基本函数julian()
并在函数中传递日期对象作为参数来确定两个日期之间的差异。它忽略了闰秒。
Syntax: julian(x, origin)
Parameters:
x: represents date object
origin: represents another date object from where difference has to be computed
示例 1:
# Define date objects
x <- as.Date("2020-06-18")
origin_date <- as.Date("2015-05-01")
# Difference between dates
julian(x, origin_date)
输出:
[1] 1875
attr(, "origin")
[1] "2015-05-01"
示例 2:
# Define date objects
x <- as.Date("2020-06-18")
origin_date <- as.Date("1920-06-18")
# Find difference between dates
julian(x, origin_date)
输出:
[1] 36525
attr(, "origin")
[1] "1920-06-18"