在R中转换年份和年中的日期

时间:2016-10-28 14:09:28

标签: r date time-series

是否可以将分数年和日期转换为R?

中的实际日期格式

例如,在我下面的示例数据的time列中,1900.00对应于1900年1月,1900.08对应于2月。 dayofyr对应于年份。

myData< - 结构(列表(时间= c(1900,1900,1900,1900,1900,1900,1900, 1900,1900,1900,1900,1900,1900,1900,1900,1900,1900,1900, 1900,1900,1900,1900,1900,1900,1900,1900,1900,1900,1900, 1900,1900,1900.08,1900.08,1900.08,1900.08,1900.08,1900.08, 1900.08,1900.08,1900.08,1900.08,1900.08,1900.08,1900.08, 1900.08,1900.08,1900.08,1900.08,1900.08,1900.08,1900.08, 1900.08,1900.08,1900.08,1900.08,1900.08,1900.08,1900.08, 1900.08,1900.08,1900.17,1900.17,1900.17,1900.17,1900.17, 1900.17,1900.17,1900.17,1900.17,1900.17,1900.17,1900.17, 1900.17,1900.17,1900.17,1900.17,1900.17,1900.17,1900.17, 1900.17,1900.17,1900.17,1900.17,1900.17,1900.17,1900.17, 1900.17,1900.17,1900.17,1900.17,1900.17,1900.25,1900.25, 1900.25,1900.25,1900.25,1900.25,1900.25,1900.25,1900.25, 1900.25,1900.25,1900.25,1900.25,1900.25,1900.25,1900.25, 1900.25,1900.25,1900.25,1900.25,1900.25,1900.25,1900.25, 1900.25,1900.25,1900.25,1900.25,1900.25,1900.25,1900.25, 1900.33,1900.33,1900.33,1900.33,1900.33,1900.33,1900.33, 1900.33,1900.33,1900.33,1900.33,1900.33,1900.33,1900.33, 1900.33,1900.33,1900.33,1900.33,1900.33,1900.33,1900.33, 1900.33,1900.33,1900.33,1900.33,1900.33,1900.33,1900.33, 1900.33,1900.33,1900.33,1900.42,1900.42,1900.42,1900.42, 1900.42,1900.42,1900.42,1900.42,1900.42,1900.42,1900.42, 1900.42,1900.42,1900.42,1900.42,1900.42,1900.42,1900.42, 1900.42,1900.42,1900.42,1900.42,1900.42,1900.42,1900.42, 1900.42,1900.42,1900.42,1900.42,1900.42,1900.5,1900.5, 1900.5,1900.5,1900.5,1900.5,1900.5,1900.5,1900.5,1900.5, 1900.5,1900.5,1900.5,1900.5,1900.5,1900.5,1900.5,1900.5, 1900.5,1900.5,1900.5,1900.5,1900.5,1900.5,1900.5,1900.5, 1900.5,1900.5,1900.5,1900.5,1900.5,1900.58,1900.58,1900.58, 1900.58,1900.58,1900.58,1900.58,1900.58,1900.58,1900.58, 1900.58,1900.58,1900.58,1900.58,1900.58,1900.58,1900.58, 1900.58,1900.58,1900.58,1900.58,1900.58,1900.58,1900.58, 1900.58,1900.58,1900.58,1900.58,1900.58,1900.58,1900.58, 1900.67,1900.67,1900.67,1900.67,1900.67,1900.67,1900.67, 1900.67,1900.67,1900.67,1900.67,1900.67,1900.67,1900.67, 1900.67,1900.67,1900.67,1900.67,1900.67,1900.67,1900.67, 1900.67,1900.67,1900.67,1900.67,1900.67,1900.67,1900.67, 1900.67,1900.67,1900.75,1900.75,1900.75,1900.75,1900.75, 1900.75,1900.75,1900.75,1900.75,1900.75,1900.75,1900.75, 1900.75,1900.75,1900.75,1900.75,1900.75,1900.75,1900.75, 1900.75,1900.75,1900.75,1900.75,1900.75,1900.75,1900.75, 1900.75,1900.75,1900.75,1900.75,1900.75,1900.83,1900.83, 1900.83,1900.83,1900.83,1900.83,1900.83,1900.83,1900.83, 1900.83,1900.83,1900.83,1900.83,1900.83,1900.83,1900.83, 1900.83,1900.83,1900.83,1900.83,1900.83,1900.83,1900.83, 1900.83,1900.83,1900.83,1900.83,1900.83,1900.83,1900.83, 1900.92,1900.92,1900.92,1900.92,1900.92,1900.92,1900.92, 1900.92,1900.92,1900.92,1900.92,1900.92,1900.92,1900.92, 1900.92,1900.92,1900.92,1900.92,1900.92,1900.92,1900.92, 1900.92,1900.92,1900.92,1900.92,1900.92,1900.92,1900.92, 1900.92,1900.92,1900.92),dayofyr = 1:366),class = c(“tbl_df”, “tbl”,“data.frame”),row.names = c(NA,-366L),. Name = c(“time”, “dayofyr”))

1 个答案:

答案 0 :(得分:1)

使用\u2063foo foo删除小数部分,转换为附加floor的字符串,将其转换为"-01-01"类,并添加天数减1.不使用任何包。

"Date"