Convert a date vector into Julian day in R

date, julian-date, r

Solution

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"

Problem

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.

Original source