Filtering dates in dplyr

前端 未结 2 594
[愿得一人]
[愿得一人] 2021-02-05 03:31

My tbl_df:

    > p2p_dt_SKILL_A%>%
    + select(Patch,Date,Prod_DL)%>%
    + head()
      Patch       Date Prod_DL
    1  P1 2015-09-04    3.43
    2 P11         


        
2条回答
  •  有刺的猬
    2021-02-05 04:11

    Another more verbose option would be to use the function between, a shortcut for x >= left & x <= right. We need to change the days to account for the = sign, and to use as.Date (explanation here).

    p2p_dt_SKILL_A%>%
                    select(Patch,Date,Prod_DL)%>%
                    filter(between(Date, as.Date("2015-09-05"),as.Date("2015-09-17")))
    

提交回复
热议问题