我有以下data.frame:
Bounty Snickers Mars
2014-10-02 400 200 1000
2014-10-03 400 100 100
2014-10-04 100 100 500
2014-10-05 800 900 600
2014-10-06 400 300 400
2014-10-07 2000 1500 800
... ... ... ...
有没有办法选择所有下降的行,例如,周一或周末?
答案 0 :(得分:1)
尝试
df[format(as.Date(row.names(df)), '%A')=='Monday',]
# Bounty Snickers Mars
#2014-10-06 400 300 400
或weekend
一个选项是使用wday
library(lubridate)
df[wday(as.Date(row.names(df))) %in% 6:7,]
# Bounty Snickers Mars
#2014-10-03 400 100 100
#2014-10-04 100 100 500