R语言 计算日期间的时间差 – difftime()函数

R语言 计算日期间的时间差 – difftime()函数

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

语法: difftime(date1, date2, units)

参数:

date1, date2: 要计算差异的日期

单位: 天、周、月等。

例子 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")
R

输出

Time difference of 122 days
Time difference of 17.42857 weeks
R

例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")
R

输出

Time difference of 2928 hours
Time difference of 175680 mins
R

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册