[R] How to get the day of the year

Richard.Cotton at hsl.gov.uk Richard.Cotton at hsl.gov.uk
Wed Oct 1 12:44:10 CEST 2008


> I am new to R and I would like to get the day of the year from 
> numerous data in the following form:  %a %d/%b/%Y %H:%M:%S (for 
> example from Tu 10/Jul/2007 21:59:13 I would like to get 191)
> 
> Whatever I try, I get NAs.

The problem is th 'Tu' bit.  Abbreviated day-of-week names and three 
letters long.  You'll have to replace/ delete them.

datestr <- "Tu 10/Jul/2007 21:59:13"
newdatestr <- sub("Tu", "Tue", datestr)
dateval <- strptime(newdatestr, "%a %d/%b/%Y %H:%M:%S")
dateval$yday            #190

Regards,
Richie.

Mathematical Sciences Unit
HSL



------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}



More information about the R-help mailing list