简体   繁体   English

如何使用 R 计算这两个日期之间的差异?

[英]How can I calculate the difference between these two dates using R?

I have a data set which containing 2 columns with dates with the following formats:我有一个数据集,其中包含 2 列,日期格式如下:

"2027-02-20 00:00:00 CET"    and "2014-12-31 CET"

how can I calculate the difference between these two dates?如何计算这两个日期之间的差异? Or, how can I apply difftime ?或者,我如何应用difftime

Here is a useful discussion but I cannot apply it directly?! 是一个有用的讨论,但我不能直接应用它?!

I gave by myself the link (above see: Here is blue) where one can find a very similar problem but not exact the same.我自己给了一个链接(见上图:这里是蓝色),人们可以在其中找到一个非常相似但不完全相同的问题。 Unfortunately some of people do not read the question carefully.不幸的是,有些人没有仔细阅读问题。 Just one gave a useful hint.只有一个给出了有用的提示。 One dose not need any string manipulation!一剂不需要任何字符串操作!

I solved my problem, the hint of Roland was really useful.我的问题解决了,罗兰的提示真的很有用。 I did not really need any string manipulation.我真的不需要任何字符串操作。 If I apply如果我申请

difftime(strptime("2027-02-20 00:00:00 CET", format = "%Y-%m-%d"),
         strptime("2014-12-31 CET", format = "%Y-%m-%d"),units="weeks")

it works well.它运作良好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何计算 dplyr 中两个日期之间的差异(以天为单位)? R - How do I calculate the difference between two dates in dplyr (in days)? R 我如何计算 R 中两个日期之间每个月的夜数,即使它们跨越两个月? - How can I calculate the number of nights PER MONTH between two dates in R even if they are across two months? 如何计算两周内两个日期之间的差额? - How can I calculate the difference between 2 dates in weeks? 计算两个日期之间的差异 - Calculate difference between two dates 在 R 如何按组(id)计算两列日期之间的差异,但同时保留第一个可用日期作为参考 - In R how to calculate the difference between two columns dates by group (id) but whilst keeping the first available date as reference R中如何将字符格式的日期转换为数字,然后轻松计算两个日期之间的差 - in R how to convert a date in character format to numeric and then easily calculate the difference between two dates R如何计算数据框中行之间的差异 - R how can I calculate difference between rows in a data frame 如何通过R中的ID计算日期之间的平均差异 - how to calculate the average difference between dates by ID in R 如何为每个唯一ID计算R中日期之间的差异 - How to calculate the difference between dates in R for each unique id 如何为R中的不同用户计算不同购买日期之间的差异 - How to calculate difference between different dates of purchase for different users in R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM