本文介绍了将日期向量转换为R中的儒略日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一列日期格式:
16Jun10
,我想提取儒略日。
我有不同的年份。

I have a column of dates in the format: 16Jun10 and I would like to extract the Julian day.I have various years.

我已经尝试过julian和mdy.date的功能,似乎不起作用。

I have tried the functions julian and mdy.date and it doesn't seem to work.

推荐答案

尝试以下操作将类字符(即文本)转换为类 POSIXlt ,然后提取朱利安日( yday ):

Try the following to convert from class character(i.e. text) to class POSIXlt, and then extract Julian day (yday):

tmp <- as.POSIXlt("16Jun10", format = "%d%b%y")
tmp$yday
# [1] 166

有关功能设置的更多详细信息:

For more details on function settings:

?POSIXlt
?DateTimeClasses

另一个选项是使用 Date class,然后使用格式提取一个julian日(注意这个类定义1:366之间的julian天,while POSIXlt是0:365):

Another option is to use a Date class, and then use format to extract a julian day (notice that this class define julian days between 1:366, while POSIXlt is 0:365):

tmp <- as.Date("16Jun10", format = "%d%b%y")
format(tmp, "%j")
# [1] "167"

这篇关于将日期向量转换为R中的儒略日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 22:00