How to get the date from the day of the year

I am working with a dataset that looks something like this:

Year Date Day_nr Value 1976 19-02-1976 50 167 1976 19-03-1976 79 140 1978 05-03-1978 64 200 1978 05-04-1978 95 200 1999 05-05-1999 125 89 1999 20-06-1999 171 79 

It is then interesting for me to estimate the polynomial model for each year depending on the number of days as the value of x. Then I run the prediction function to estimate the model values. I do this with the numbers of the day. My data for the prediction data frame looks a bit like this with only a lot of records per year

  Year Day_nr Value 1976 53 167 1976 80 140 1978 69 300 1978 130 200 1999 140 89 1999 160 79 

What I would like to do now is to get a date from these day and year numbers. I thought I could do this with lubridate, but I could only find the opposite direction that I use to generate day numbers, primarily in the original data file. Working with the whole date as a predictor is impossible for me, since I need the day number for other calculations.

Is there any way to do this?

Cheers, Sarina

+4
source share
1 answer

Google has an answer: https://stat.ethz.ch/pipermail/r-help/2012-March/308013.html

Using the first line of the second example above as an example:

 > strptime(paste("1976", 53), format="%Y %j") [1] "1976-02-22" 
+4
source

Source: https://habr.com/ru/post/1501253/


All Articles