我的 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 2015-09-11 3.49
3 P12 2015-09-18 3.45
...
4 P13 2015-12-06 3.57
5 P14 2015-12-13 3.43
6 P15 2015-12-20 3.47
我想根据日期选择所有行,例如如果Date
大于2015-09-04
且小于2015-09-18
结果应为:
Patch Date Prod_DL
P1 2015-09-04 3.43
P11 2015-09-11 3.49
我尝试了以下方法,但返回了一个空的向量。
p2p_dt_SKILL_A%>%
select(Patch,Date,Prod_DL)%>%
filter(Date > "2015-09-04" & Date <"2015-09-18")
只返回:
> p2p_dt_SKILL_A%>%
+ select(Patch,Date,Prod_DL)%>%
+ filter(Date > 2015-09-12 & Date <2015-09-18)
Source: local data table [0 x 3]
Variables not shown: Patch (fctr), Date (date), Prod_DL (dbl)
也尝试使用引号。
并且使用 lubridate
p2p_dt_SKILL_A%>%
select(Patch,Date,Prod_DL)%>%
#filter(Date > 2015-09-12 & Date <2015-09-18)%>%
filter(Patch %in% c("BVG1"),month(p2p_dt_SKILL_A$Date) == 9)%>%
arrange(Date)
但这给了我整个9月份的数据。
是否有更有效的方法,例如在dplyr
中使用Date
类型变量上的between
运算符?
date
对象还是其他什么东西。 - Pierre Lapointe变量未显示:Patch(fctr),Date(date),Prod_DL(dbl)
... 它是一个日期类型。 - Sherytbl_df
类型。 - Shery