如何确定日期是否为周末(不使用lubridate) [英] How to determine if date is a weekend or not (not using lubridate)

查看:138
本文介绍了如何确定日期是否为周末(不使用lubridate)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日期对象的向量( yyyy-mm-dd ),我想确定其中的任何一个是否在周末。有一个功能可以确定这个直截了当吗?

I have a vector of date objects (yyyy-mm-dd) and I want to determine if any of them are on weekend or not. Is there a function that can determine this straightaway?

我可以在 lubridate 包中使用 wday(),然后确定是否返回价值是 01 07 ,但其他更简单的东西?

I can use wday() in the lubridate package and then determine if returned value is 01 or 07, but anything else more straightforward?

x <- seq(Sys.Date()-10, Sys.Date(), by = 1)
x[lubridate::wday(x) %in% c(1, 7)]


推荐答案

AnandaMahto的建议在这里而不是一个评论:

I put @AnandaMahto's suggestion here rather than a comment:

library(chron)
x <- seq(Sys.Date()-10, Sys.Date(), by = 1)
x[is.weekend(x)]

## [1] "2014-10-11" "2014-10-12" "2014-10-18"

这篇关于如何确定日期是否为周末(不使用lubridate)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆