On 01-Oct-08 10:44:10, [EMAIL PROTECTED] wrote: >> 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
In addition to the above: BEWARE that strptime(...)$yday counts upwards from 0 to 364 (normal year) or 365 (leap year). In other words, 1 Jan is day 0. Hence Richard got the result 190 where you expected 191. So add 1 to get the answer everyone expects! Best wishes, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <[EMAIL PROTECTED]> Fax-to-email: +44 (0)870 094 0861 Date: 01-Oct-08 Time: 12:24:12 ------------------------------ XFMail ------------------------------ ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.