Eduardo M. A. M.Mendes
2011-Jul-26 21:49 UTC
[R] How to use as.Date (or something else) with "31-Jul-2010 23:59:00"
Hello I have a huge file (not an R-file) in which the first column is a string with date, hour, minutes and seconds (For instance, "31-Jul-2010 23:59:00"). I tried as.Date but the error msg was "Error in charToDate(x) : character string is not in a standard unambiguous format". I have checked the help for the function as well as date but to no avail. How can that sort of string be transformed to something useful in R? Many thanks Ed
Clint Bowman
2011-Jul-26 22:32 UTC
[R] How to use as.Date (or something else) with "31-Jul-2010 23:59:00"
?strptime -- 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, 26 Jul 2011, Eduardo M. A. M.Mendes wrote:> Hello > > I have a huge file (not an R-file) in which the first column is a string > with date, hour, minutes and seconds (For instance, "31-Jul-2010 23:59:00"). > > I tried as.Date but the error msg was "Error in charToDate(x) : > character string is not in a standard unambiguous format". > > I have checked the help for the function as well as date but to no avail. > > How can that sort of string be transformed to something useful in R? > > Many thanks > > Ed > > ______________________________________________ > 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. >
Eduardo Mendes
2011-Jul-26 23:18 UTC
[R] How to use as.Date (or something else) with "31-Jul-2010 23:59:00"
Hello again I do apologize for the previous email without any useful information that can lead to an answer. To those who felt offended by "to no avail", I do apologize again. I guess I will be always a newbie as far as R is concerned. The date format was wrong and although I have tried to use different formats I could not get the result I wanted. So I went back to the file and changed to a format that R can understand (Please understand that R is very likely to have package that I might be unaware of). Now all dates are> class(data$TempDate)[1] "POSIXct" "POSIXt"> data$TempDate[1:2][1] "2010-06-27 00:00:00 BRT" "2010-06-27 00:01:00 BRT" If I issue the command as.Date(data$TempDate[2]), the information on hour, minute and second is lost as.Date(data$TempDate[2]) [1] "2010-06-27" If I use data$TempDate in a zoo object, I got the following msg some methods for "zoo" objects do not work if the index entries in 'order.by' are not unique If I issue plot(zoo object), the result is a mess since many values do not have an unique entry (as expected). How can I use the information on data$TempDate to create unique indexes for zoo objects and the like? Many thanks. Ed PS. If the problem is not clearly stated, please be patient and tell me what is obscure and needs clarification. On Tue, Jul 26, 2011 at 6:49 PM, Eduardo M. A. M.Mendes < emammendes@gmail.com> wrote:> Hello > > I have a huge file (not an R-file) in which the first column is a string > with date, hour, minutes and seconds (For instance, "31-Jul-2010 > 23:59:00"). > > I tried as.Date but the error msg was "Error in charToDate(x) : > character string is not in a standard unambiguous format". > > I have checked the help for the function as well as date but to no avail. > > How can that sort of string be transformed to something useful in R? > > Many thanks > > Ed > >[[alternative HTML version deleted]]