0

I have files that are named according to year and day of year. How do I convert day of year to month?

Basic example:

library(tidyverse)
library(lubridate)
(mydates <- 
  tibble(year = c(2010, 2020),
          dayofyear = c(001, 365),
         yearday = c(2010001, 2020365)))


mydates %>% mutate(dayofyear = yday(dayofyear))
mydates %>% mutate(yearday = yday(yearday))
derelict
  • 3,657
  • 3
  • 24
  • 29
  • 1
    You can use `date = strptime(yearday, format = "%Y%j")`. (And of course once you have converted to `Date` you can extract the month with `month`, `month(strptime(...))`) Your `yday` doesn't work because it's for converting in the opposite direction, getting the day of year from a Date. – Gregor Thomas Sep 22 '22 at 01:23

0 Answers0