如何从一年中的某天获取日期 [英] How to get a date from day of year

查看:111
本文介绍了如何从一年中的某天获取日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用看起来像这样的数据集:

I am working with a data set that looks a bit 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

然后,我有兴趣根据天数作为x值来估算每年的多项式模型.然后,我运行一个预测函数以估计模型的值.我用天数来做到这一点. 然后,用于预测数据帧的我的数据"看起来有点像这样,每年有更多的条目

I am then interested to estimate a polynomial model for each year depending on the day number as a x value. I then run a predict function to estimate the values of the model. I do that with the day numbers. My Data for the predict data frame then looks a bit like this just with more entries per year

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

我现在想做的是从这些天数和年份中获取日期. 我以为我可以用lubridate来做到这一点,但是我只能找到与原始数据文件中最初生成日期数字相反的方向.我无法将整个日期用作预测变量,因为我需要将日数用于其他计算.

What I now would like to do is get a date out of these day numbers and the year. I thought I could do it with lubridate but I could only find the opposite direction which I use to generate the day numbers in the first place in the original data file. Working with the whole date as a predictor is not possible for me as I need the day number for other calculations.

有没有一种方法可以轻松做到这一点?

Is there a way to easily do that?

干杯, 萨里纳(Sarina)

Cheers, Sarina

推荐答案

Google似乎有一个答案:

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

以上面第二组中的第一行为例:

Using first line from second set above as an example:

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

这篇关于如何从一年中的某天获取日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆