- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有形式为 yyyy-ww
的周日期数据哪里ww
是两位数的周数。数据跨度2007-01
至 2010-30
.周计数惯例是 ISO 8601,正如您在此处看到的 on Wikipedia's "Week number" article ,偶尔达到一年 53 周。例如,2009 年有 53 周,请参阅 this ISO 8601 calendar 中的周数。 . (参见其他年份;根据维基百科文章,第 53 周相当罕见。)
基本上我想读取周日期,将其转换为 Date
对象并将其保存到 data.frame
中的单独列中.作为测试,我重新转换了 Date
反对 yyyy-ww
格式 format([Date-object], format = "%Y-%W"
,这在 2009-53
抛出了一个错误.该周未能被 R
解释为日期.这很奇怪,因为其他没有第 53 周(在 ISO 8601 标准中)的年份转换得很好,例如 2007-53
,而其他也没有第 53 周(在 ISO 8601 标准中)的年份也会失败,例如 2008-53
以下最小示例演示了该问题。
最小的例子:
dates <- c("2009-50", "2009-51", "2009-52", "2009-53", "2010-01", "2010-02")
as.Date(x = paste(dates, 1), format = "%Y-%W %w")
# [1] "2009-12-14" "2009-12-21" "2009-12-28" NA "2010-01-04"
# [6] "2010-01-11"
other.dates <- c("2007-53", "2008-53", "2009-53", "2010-53")
as.Date(x = paste(other.dates, 1), format = "%Y-%W %w")
# [1] "2007-12-31" NA NA NA
R
接受 ISO 8601 格式的周数?
最佳答案
包裹ISOweek
管理 ISO 8601 样式周编号,与 Date
相互转换R
中的对象.见 ISOweek
更多。继续上面的示例日期,我们首先需要稍微修改格式。它们必须采用形式 yyyy-Www-w
而不是 yyyy-ww
,即 2009-W53-1
.最后一位数字标识用于标识星期的星期几,在这种情况下是星期一。周数必须是两位数。
library(ISOweek)
dates <- c("2009-50", "2009-51", "2009-52", "2009-53", "2010-01", "2010-02")
other.dates <- c("2007-53", "2008-53", "2009-53", "2010-53")
dates <- sub("(\\d{4}-)(\\d{2})", "\\1W\\2-1", dates)
other.dates <- sub("(\\d{4}-)(\\d{2})", "\\1W\\2-1", other.dates)
## Check:
dates
# [1] "2009-W50-1" "2009-W51-1" "2009-W52-1" "2009-W53-1" "2010-W01-1"
# [6] "2010-W02-1"
(iso.date <- ISOweek2date(dates)) # deal correctly
# [1] "2009-12-07" "2009-12-14" "2009-12-21" "2009-12-28" "2010-01-04"
# [6] "2010-01-11"
(iso.other.date <- ISOweek2date(other.dates)) # also deals with this
# [1] "2007-12-31" "2008-12-29" "2009-12-28" "2011-01-03"
## Check that back-conversion works:
all(date2ISOweek(iso.date) == dates)
# [1] TRUE
## This does not work for the others, since the 53rd week of
## e.g. 2008 is back-converted to the first week of 2009, in
## line with the ISO 6801 standard.
date2ISOweek(iso.other.date) == other.dates
# [1] FALSE FALSE TRUE FALSE
关于r - R 中的第 53 周?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14937837/
moment.js 库很棒,我几乎一直都在使用它,但我最近遇到了一些有趣的事情。我正在尝试按一年中的一周绘制数据,其中一个数据点是 2013 年 12 月 31 日,moment.js 告诉我这是第
有没有办法可以找到给定一年的最后一周的数字。 例如,对于年份 2018 , 2018 的最后一周数是 52。 年份 2015 , 上周数字是 53。 最佳答案 如果您指的是 ISO 周,那么您可以使用
我正在尝试创建一个 if 语句,该语句根据当前日期检查日期,如果日期少于 2 周,则抛出 错误。 我当前的代码 const moment = require('moment') const today
转换 Spark 数据帧 +----+---------+------+ |name|date |amount| +----+---------+------+ |Jhon|4/6/2018
我有这段代码,我想在从日期选择器获取的日期中添加 40 周,并在将 40 周(280 天)添加到从日期选择器获取的日期后获取新日期。 代码: public class MainActivity ext
我的 table 上有一个 timestamp字段,这是一个标准的 RethinkDB 日期字段。 我可以使用此时间戳字段按天/周/月对行进行分组吗?在 group() 文档中找不到任何示例。 最佳答
当用户单击日/周/月按钮时,我需要运行一些 Javascript 代码来重新加载日历。是否有类似 dayButtonClicked() 之类的回调? 发生BUG: 当我第一次加载日历时。最初的 Vie
当我收到年份、周数和星期几时,如何在 C# 中计算日期。例如:年份 = 2011周 = 27天 = 6 结果应该是 2011-7-10 感谢大家。我根据维基百科算法解决了它。 最佳答案 此处没有 C#
如何使用 c#.net 每天、每周和每月发送电子邮件? 我正在考虑创建一个 Windows 服务应用程序,但我不知道该怎么做,也不知道该怎么做。 非常感谢您的想法。 最佳答案 Windows 服务可能
最近我在处理全日历。我想更改周 View 中日期的格式。我发现很多人使用 columnFormat: { month: 'ddd', week: 'ddd d/M', day: 'dddd d/M'
我正在使用一个完整的日历插件来显示各种事件。 我的问题是,当我更改正在查看的月份/周,然后刷新时,我会回到当前的月份/周,而我想留在之前查看的同一个月/周。即如果现在是八月,我回到七月,然后刷新,我希
我有一个按周计算所有工单的查询,但我需要将其转换为动态两行报告,将周开始日期移动到列中? 这就是我试图让它做的事情.. 这是我的查询: SELECT td_type, FROM_DAYS(TO_DAY
我想获取某件事的统计数据。 我正在尝试统计今天、本周、本月的情况。 我的查询: "SELECT COUNT(id) FROM images i WHERE i.user_id = 3 GROUP BY
我正在开发一个有 200.000 个页面的网站。还有一个浏览部分,显示最受欢迎、评价最高等文档。然而,在发布几周后,此部分将变得几乎静态。所以我还想实现一个过滤系统,它将显示今天、本周、本月最受欢迎的
如何从字段日期早于现在 + 2 周的 MySQL 数据库中获取行? 我试过了 WHERE date_ready < DATE_SUB(CURDATE(), INTERVAL 2 WEEK) 但这不是我
我有下表: create table my_table ( SubjectID int, Date Date, Test_Value int ); insert into my_table(Su
好吧,这几天我一直在努力解决这个问题。我是一个 super 初学者,我有一个标签。在该标签中,我显示了日期 1/20/21。我能够做到这一点。然后我有一个按钮。我希望每次单击该按钮都会将日期增加 14
我有一个数据集,其中包含工厂 worker 三年产出的数据。现在我想获得基于日期、周、月的平均输出。问题是日期格式类似于 %d.%m.%Y(日-月-年)。我的问题是如何在保持日期格式不变的同时获得预期
我有这样的东西 DateTime.Now.ToString("dd.MM.yy"); 在我的代码中,我需要添加 1 周,比如 5.4.2012 变成12.4.2012 我试过转成int再累加,但是到3
我已经阅读了几篇关于在 mysql 查询中估计移动平均值的文章,但是我的情况似乎稍微困难一些,因为该表不包含我想要计算平均值的列。我需要计算每组的行数,并显示该组的移动平均值。 表中基本上只有一列相关
我是一名优秀的程序员,十分优秀!