r - 从日期序列中删除闰日
问题描述
我试图从我的日期序列中删除闰日,但是,我收到了错误。请帮忙。
Dates=as.data.frame(seq(as.Date("1979-01-01"), to=as.Date("2016-12-31"),by="days"))
names(Dates)= "Dates"
Dates$year=as.numeric(format(Dates$Dates, "%Y"))
Dates$month=as.numeric(format(Dates$Dates, "%m"))
Dates$day=as.numeric(format(Dates$Dates, "%d"))
if [(Dates$month == 2 & Dates$day == 29)]
Dates=Dates[]
没有闰日的日期序列
解决方案
也许你搞砸了数据框和向量?可以考虑下面的代码和库tidyverse
和library(lubridate)
:
> Dates=seq(as.Date("1979-01-01"), to=as.Date("2016-12-31"),by="days")
> find_leap = function(x){
+ day(x) == 29 & month(x) == 2
+ }
>
> Dates[find_leap(Dates)]
[1] "1980-02-29" "1984-02-29" "1988-02-29" "1992-02-29" "1996-02-29"
[6] "2000-02-29" "2004-02-29" "2008-02-29" "2012-02-29" "2016-02-29"
推荐阅读
- javascript - 如何在上传图像之前检查 Angular 中的图像方向
- neo4j - 大规模识别二级连接
- azure-devops - Invoke-SqlCmd for migrations 脚本在将要引入的列上失败
- java - 无法停止改装发送
- spring-boot - 无法使用 PCF 配置服务器服务中的配置客户端应用程序读取属性值
- node.js - 在接受请求之前等待数据库连接
- python - pandas 到 html 样式的表级格式
- azure - 损坏的 Azure 虚拟机
- c# - 无法加载文件或程序集“MySql.Data”参数不正确
- android - 已安装硬件加速,但 Visual Studio for Mac 找不到它。我该如何进行?