简体   繁体   English

在执行seq函数时如何解决错误?

[英]How do I solve error in executing seq function?

I am running the following code, in order to get all the dates from 22th of jan 2014 untill the second of feb 2014. However, I get an error that I do not understand (as I follow the code on the page of the function: https://www.rdocumentation.org/packages/base/versions/3.5.2/topics/seq.Date ) 我正在运行以下代码,以便获取从2014年1月22日到2014年2月2日的所有日期。但是,我得到了一个我不理解的错误(因为我遵循函数页面上的代码: https://www.rdocumentation.org/packages/base/versions/3.5.2/topics/seq.Date

seq(as.Date("22/01/2014"), as.Date("02/02/2014"), "days")

gives me the following error: 给我以下错误:

 Error in seq.int(0, to0 - from, by) : wrong sign in 'by' argument

What is going wrong here? 这是怎么了?

Try debugging your code. 尝试调试您的代码。 Does every part resolve as you expect? 是否每个部分都能按预期解决? Compare to the examples and see which differences there are: 与示例进行比较,看看有哪些区别:

Them: seq(as.Date("1910/1/1"), as.Date("1999/1/1"), "days")
You   seq(as.Date("22/01/2014"), as.Date("02/02/2014"), "days")

Can you run the example? 您可以运行该示例吗? If not, something sinister is going on in your environment. 如果没有,那么您的环境中正在发生某种危险的事情。

Does your code match the example? 您的代码与示例匹配吗? Try modifying the example, one part at a time, to match what you are trying to. 尝试一次修改该示例,使其与您要尝试的内容相匹配。

Perhaps it's the date format. 也许是日期格式。 Try executing a small part of the code: 尝试执行一小段代码:

as.Date("22/01/2014")
[1] "0022-01-20"

Does this look right? 这看起来正确吗? Perhaps as.Date doesn't understand American date formats. 也许as.Date无法理解美国日期格式。 Try modifying your code: 尝试修改您的代码:

seq(as.Date("2014-01-22"), as.Date("2014-02-02"), by="days")
[1] "2014-01-22" "2014-01-23" "2014-01-24" "2014-01-25" "2014-01-26" "2014-01-27" "2014-01-28" "2014-01-29" "2014-01-30" "2014-01-31" "2014-02-01"
[12] "2014-02-02"

Try some of this options: 尝试以下一些选项:

seq.Date(as.Date("2014/01/22"), as.Date("2014/02/02"), by="days")
seq.Date(as.Date("22/01/2014", format="%d/%m/%Y"), as.Date("02/02/2014", format="%d/%m/%Y"), by="days")
seq(as.Date("2014/01/22"), as.Date("2014/02/02"), by="days")
seq(as.Date("22/01/2014", format="%d/%m/%Y"), as.Date("02/02/2014", format="%d/%m/%Y"), by="days")

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM