R - Removing weekends from dataframe in R

2019-09-11 04:35发布

My data looks like this for one column:

Date    AED.USD
03/01/2005  3.6726
04/01/2005  3.6726
05/01/2005  3.6725
06/01/2005  3.6726
07/01/2005  3.6725
08/01/2005  NA
09/01/2005  NA
10/01/2005  3.6726
11/01/2005  3.6725
12/01/2005  3.6726
13/01/2005  3.6725
14/01/2005  3.6726
15/01/2005  NA
16/01/2005  NA
17/01/2005  3.6725
18/01/2005  3.6726
19/01/2005  3.6725
20/01/2005  3.6725
21/01/2005  3.6725

I want to remove the dates with the weekends, I have tried using

x <- seq(as.Date("2005-01-03"),as.Date("2016-11-30"),by = 1)
x <- fxdl_weekdays[!weekdays(x) %in% c('Saturday','Sunday')]

this shows the dates in the values section but how am I supposed to show this in an updated data frame.

1条回答
三岁会撩人
2楼-- · 2019-09-11 05:09
df[which(weekdays(as.Date(df$Date, format = "%m/%d/%Y"))
          %in% c('Monday','Tuesday', 'Wednesday', 'Thursday', 'Friday')), ]
查看更多
登录 后发表回答