mdkzone at aol.com
2011-Jul-19 20:38 UTC
[R] timeDate with month designated by three letters.
Dear R Experts: I am trying to convert a date and time character field to timeDate where the month is presented as three letters, such as "JUN" for June, etc. This is an example of the full character field: "04-MAY-11 1428" What is the proper format syntax? I've tried timeDate("04-MAY-11 1428",format="%d-%m-%y %H%M") but only get GMT [1] [NA] If I change the month to a number as below, then it works, but that would require recoding of the data field. timeDate("04-05-11 1428",format="%d-%m-%y %H%M") gives GMT [1] [2011-05-04 14:28:00] which is correct. How do I get R to recognize the month as a 3 letter designator. Any recommendations you can provide would be greatly appreciated. Michael [[alternative HTML version deleted]]
Tena koe Michael The help file for strptime suggests you should be using %b (three letter month) rather than %m (decimal number month). HTH .... Peter Alspach> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of mdkzone at aol.com > Sent: Wednesday, 20 July 2011 8:39 a.m. > To: R-help at r-project.org > Subject: [R] timeDate with month designated by three letters. > > Dear R Experts: > > > I am trying to convert a date and time character field to timeDate > where the month is presented as three letters, such as "JUN" for June, > etc. > > > This is an example of the full character field: > > > "04-MAY-11 1428" > What is the proper format syntax? > > > I've tried > > timeDate("04-MAY-11 1428",format="%d-%m-%y %H%M") > but only get > > GMT > [1] [NA] > If I change the month to a number as below, then it works, but that > would require recoding of the data field. > > > > timeDate("04-05-11 1428",format="%d-%m-%y %H%M") > > gives > > GMT > [1] [2011-05-04 14:28:00] > which is correct. How do I get R to recognize the month as a 3 letter > designator. > > > Any recommendations you can provide would be greatly appreciated. > > > Michael > > > [[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.The contents of this e-mail are confidential and may be subject to legal privilege. If you are not the intended recipient you must not use, disseminate, distribute or reproduce all or any part of this e-mail or attachments. If you have received this e-mail in error, please notify the sender and delete all material pertaining to this e-mail. Any opinion or views expressed in this e-mail are those of the individual sender and may not represent those of The New Zealand Institute for Plant and Food Research Limited.
> strptime("04-MAY-11 1428",format="%d-%b-%y %H%M")[1] "2011-05-04 14:28:00" -- Clint Bowman INTERNET: clint at ecy.wa.gov Air Quality Modeler INTERNET: clint at math.utah.edu Department of Ecology VOICE: (360) 407-6815 PO Box 47600 FAX: (360) 407-7534 Olympia, WA 98504-7600 USPS: PO Box 47600, Olympia, WA 98504-7600 Parcels: 300 Desmond Drive, Lacey, WA 98503-1274 On Tue, 19 Jul 2011, mdkzone at aol.com wrote:> Dear R Experts: > > > I am trying to convert a date and time character field to timeDate where the month is presented as three letters, such as "JUN" for June, etc. > > > This is an example of the full character field: > > > "04-MAY-11 1428" > What is the proper format syntax? > > > I've tried > > timeDate("04-MAY-11 1428",format="%d-%m-%y %H%M") > but only get > > GMT > [1] [NA] > If I change the month to a number as below, then it works, but that would require recoding of the data field. > > > > timeDate("04-05-11 1428",format="%d-%m-%y %H%M") > > gives > > GMT > [1] [2011-05-04 14:28:00] > which is correct. How do I get R to recognize the month as a 3 letter designator. > > > Any recommendations you can provide would be greatly appreciated. > > > Michael > > > [[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. >