R - Removing weekends from dataframe in R

谁说胖子不能爱 提交于 2019-12-25 07:58:06

问题


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:


df[which(weekdays(as.Date(df$Date, format = "%m/%d/%Y"))
          %in% c('Monday','Tuesday', 'Wednesday', 'Thursday', 'Friday')), ]


来源:https://stackoverflow.com/questions/42013199/r-removing-weekends-from-dataframe-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!