📜  在 R 编程中计算日期之间的时间差 - difftime()函数

📅  最后修改于: 2022-05-13 01:54:42.001000             🧑  作者: Mango

在 R 编程中计算日期之间的时间差 - difftime()函数

R 语言中的difftime()函数用于以所需的单位(如天、周、月、年等)计算日期之间的时间差。

示例 1:

# R program to find time difference
  
# Calling difftime() function
difftime("2020-5-16", "2020-1-15", units = "days")
difftime("2020-5-16", "2020-1-15", units = "weeks")

输出:

Time difference of 122 days
Time difference of 17.42857 weeks

示例 2:

# R program to find time difference
  
# Calling difftime() function
difftime("2020-5-16", "2020-1-15", units = "hours")
difftime("2020-5-16", "2020-1-15", units = "mins")

输出:

Time difference of 2928 hours
Time difference of 175680 mins