【问题标题】:Filter out business days from dates column in a dataframe in R从 R 中数据框中的日期列中过滤掉工作日
【发布时间】:2017-11-07 05:58:37
【问题描述】:

我有一个包含 2 列日期和销售额的数据框。如何从数据框中仅过滤工作日。尝试了以下代码,但它不起作用:

dataset <- subset(SalesData, SlaesData$BusinessDate >= "2016-02-05", SalesData$BusinessDate[isWeekday(SalesData$BusinessDate)])

【问题讨论】:

    标签: r date


    【解决方案1】:
    library(chron)
    #sample data
    df <- data.frame(report_date=as.Date(c('2017-11-07','2017-11-05','2017-11-04')), sales=c(100,200,400))
    
    #subset of sample data having only business days
    df[!is.weekend(df$report_date),]
    

    【讨论】:

      猜你喜欢
      • 2016-08-11
      • 2014-02-28
      • 2020-02-03
      • 2018-06-24
      • 2016-10-29
      • 2022-11-22
      • 2022-12-21
      • 1970-01-01
      • 2019-05-04
      相关资源
      最近更新 更多