[R] julian day form POSIXt object

David Winsemius dwinsemius at comcast.net
Fri Sep 30 16:14:26 CEST 2011

On Sep 30, 2011, at 4:47 AM, maxbre wrote:

> here is an alternative long and winded solution to the problem  
> sticking on
> the julian function of chron package
> test$year <- as.integer(as.character(test$date, "%Y"))
> test$month <- as.integer(as.character(test$date, "%m"))
> test$day <- as.integer(as.character(test$date, "%d"))
> test$hour <- as.integer(as.character(test$date, "%H"))
> test$jday <-julian(test$month,test$day,test$year,origin=c(month=1,  
> day=0,
> year=test$year))
> thank you all for helping me in sorting out the problem
> by the way I like very much this very compact solution
> test$doy <- as.POSIXlt(test$date)$yday+1
> but on the other hand I'm still struggling to fully understand it,
> especially for what is concerning the part after $: so what is $yday  
> for?

POSIXlt objects are represented as lists. as.POSIXlt will convert a  
POSIXct object to that class.  The "yday" element is the number of  
days that have passed since the first day of the year. The "$"  
operator accesses list elements by name.

?Extract   #  same as ?"["

> if someone would be so kind to explain me this part I would be very  
> grateful
> a newbie in R
> lesson learned

David Winsemius, MD
West Hartford, CT

More information about the R-help mailing list