-2

I have a set of paired data. One column is a Date, formated as mdY, the other a corresponding datapoint.

The dates are daily.

I would like to extract the date and data that is recorded on friday (the last day of the working week), to make the data weekly. The next thing I would like to do is reformat the Date to YMD so that it matches another dataset I have.

How can this be achieved in R?

Thanks in advance.

  • See `?as.Date` for converting your data to an actual Date class. When that's done, it will display as YMD by default and you can use the `wday` function to get the day of the week. If you need help writing the code, share a reproducible example and show what you've tried. [Here is s tutorial on writing reproducible examples in R](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Gregor Thomas Apr 16 '18 at 14:43
  • Look at the package lubridate: http://lubridate.tidyverse.org/ – Ron Jensen Apr 16 '18 at 14:46

1 Answers1

0

Hard to answer without example data. Something along these lines might help:

library(dplyr)
library(lubridate)

df %>%
  mutate(Date = mdy(Date)) %>%
  filter(wday(Date) == 6) # 6 = Friday
Martin Schmelzer
  • 23,283
  • 6
  • 73
  • 98