I have a column of dates in the format: 16Jun10 and I would like to extract the Julian day. I have various years.
I have tried the functions julian and mdy.date and it doesn't seem to work.
You can use R's insol package which has a JD(x, inverse=FALSE) function which converts POSIXct to Julian Day Number (JDN). insol package also has JDymd(year,month,day,hour=12,minute=0,sec=0) for custom dates.
A Julian date is sometimes used to refer to a date format that is a combination of the current year and the number of days since the beginning of the year. For example, January 1, 2007 is represented as 2007001 and December 31, 2007 is represented as 2007365.
Multiply the number of non-leap years by 365, and the number of leap years by 366. Add the two totals together for a total number of days in all years.
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
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With