Hello, 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. Well... I need your help, please! Thanks in advance Yours sincerely, Solène Goy _________________________________________________________________ [[elided Hotmail spam]] [[alternative HTML version deleted]]
> 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}}
In addition to Richard, try this also: format(strptime(newdatestr, "%a %d/%b/%Y %H:%M:%S"), "%j") On Wed, Oct 1, 2008 at 5:42 AM, Solene Goy <olsen-olsen at hotmail.fr> wrote:> > Hello, > 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. > > Well... I need your help, please! > Thanks in advance > Yours sincerely, > Sol?ne Goy > _________________________________________________________________ > > [[elided Hotmail spam]] > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help at 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. > >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
On Wed, 2008-10-01 at 08:42 +0000, Solene Goy wrote:> Hello, > 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.Tu isn't a valid abbreviated for for the day (in my locale at least), which might explain the NAs and you don't show how you tried to get the julien day. Here are two ways that work.> tmp <- as.Date("Tue 10/Jul/2007 21:59:13", format = "%a %d/%b/%Y %H:%M:%S") > tmp[1] "2007-07-10"> format(tmp, "%j")[1] "191"> as.numeric(format(tmp, "%j"))[1] 191> tmp <- as.POSIXlt("Tue 10/Jul/2007 21:59:13", format = "%a %d/%b/%Y %H:%M:%S") > tmp[1] "2007-07-10 21:59:13"> format(tmp, format = "%j")[1] "191"> as.numeric(format(tmp, format = "%j"))[1] 191 Is this what you wanted? G> > Well... I need your help, please! > Thanks in advance > Yours sincerely, > Solne Goy > _________________________________________________________________ > > [[elided Hotmail spam]] > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20081001/826f94a4/attachment.bin>