[英]Specific date format conversion problems in R
Basically I want to know why as.Date(200322,format="%Y%W")
gives me NA
. 基本上我想知道为什么
as.Date(200322,format="%Y%W")
给我NA
。 While we are at it, I would appreciate any advice on a data structure for repeated cross-section (aka pseudo-panel) in R. I did get aggregate()
to (sort of) work, but it is not flexible enough - it misses data on columns when I omit the missed values, for example. 在讨论过程中,我会很感谢R中关于重复横截面(即伪面板)的数据结构的任何建议。我确实得到了
aggregate()
用于(某种)工作,但它不够灵活-它例如,当我忽略遗漏的值时,遗漏了列上的数据。 Specifically, I have a survey that is repeated weekly for a couple of years with a bunch of similar questions answers to which I would like to combine, average, condition and plot in both dimensions. 具体来说,我进行了一项调查,该调查每周重复进行数年,并提出了一系列类似的问题,我希望在两个维度上对其进行合并,平均,状况和绘图。 Getting the date conversion right should presumably help me towards my goal with zoo package or something similar.
正确地进行日期转换应该可以帮助我实现与动物园配套或类似产品有关的目标。
Any input is appreciated. 任何输入表示赞赏。
Update: thanks for string suggestion, but as you can see in your own example, %W
part doesn't work - it only identifies the year while setting the current day while I need to set a specific week (and leave the day blank). 更新:感谢您提出的字符串建议,但是正如您在自己的示例中看到的那样,
%W
部分不起作用-它仅在设置当前日期时标识年份,而我需要设置特定的星期(并将日期留空) 。
Use a string as first argument in as.Date()
and select a specific weekday (format %w
, value 0-6). 在
as.Date()
使用字符串作为第一个参数,然后选择一个特定的工作日(格式%w
,值0-6)。 There are seven possible dates in each week, therefore strptime
needs more information to select a unique date. 每周有七个可能的日期,因此
strptime
需要更多信息来选择唯一的日期。 Otherwise the current day and month are returned. 否则,返回当前的日期和月份。
> as.Date(paste("200947", "0", sep="-"), format="%Y%W-%w")
[1] "2009-11-22"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.