Dear R-users, I use unlist of POSIX dates to extract the year, hour etc. With that I can search for files in my database which are in the form 'yyyymmddhh_synops.txt' However, I get stucked during midnight where unlist just gives NA's. The script is given below, the problem accurs at acc.period[16] (midnight). However when I write out the character, unlist works well. But as.character(acc.period[16]) is not the solution.... begin=paste(dates[i]-1,"09:00:00") end=paste(dates[i],"08:00:00") acc.period=seq(as.POSIXct(begin),as.POSIXct(end),"hour") unlist(strptime(acc.period[16],format="%Y-%m-%d %H:%M:%S")) # sec min hour mday mon year wday yday isdst # NA NA NA NA NA NA NA NA -1 unlist(strptime(acc.period[17],format="%Y-%m-%d %H:%M:%S")) # sec min hour mday mon year wday yday isdst # 0 0 1 1 2 106 3 59 0 a="2006-03-01 00:00:00" unlist(strptime(a,format="%Y-%m-%d %H:%M:%S")) # sec min hour mday mon year wday yday isdst # 0 0 0 1 2 106 3 59 0 Could someone help? Thanks in advance! Hanneke -- --------------------------------------------- ir J.M. (Hanneke) Schuurmans PhD student Hydrology Department of Physical Geography Faculty of Geosciences - Universiteit Utrecht P.O. Box 80115 3508 TC Utrecht T +31 (0)30 2532988 F +31 (0)30 2531145 W www.geo.uu.nl/staff/schuurmans
On Wed, 17 Jan 2007, Hanneke Schuurmans wrote:> Dear R-users, > > I use unlist of POSIX dates to extract the year, hour etc. With that I > can search for files in my database which are in the form > 'yyyymmddhh_synops.txt' > However, I get stucked during midnight where unlist just gives NA's. > The script is given below, the problem accurs at acc.period[16] > (midnight). However when I write out the character, unlist works well. > But as.character(acc.period[16]) is not the solution.... > > begin=paste(dates[i]-1,"09:00:00") > end=paste(dates[i],"08:00:00") > acc.period=seq(as.POSIXct(begin),as.POSIXct(end),"hour") > > unlist(strptime(acc.period[16],format="%Y-%m-%d %H:%M:%S")) > # sec min hour mday mon year wday yday isdst > # NA NA NA NA NA NA NA NA -1 > unlist(strptime(acc.period[17],format="%Y-%m-%d %H:%M:%S")) > # sec min hour mday mon year wday yday isdst > # 0 0 1 1 2 106 3 59 0 > > a="2006-03-01 00:00:00" > unlist(strptime(a,format="%Y-%m-%d %H:%M:%S")) > # sec min hour mday mon year wday yday isdst > # 0 0 0 1 2 106 3 59 0 > > Could someone help?Please see the footer comment> PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.We do need that to help you. Using unclass() rather than unlist() will help us see what strptime actually returned (I suspect the NAs are from there as your (unshown) input was invalid, e.g. had hour=24). We also need the other information the posting guide asks for, such as the output of sessionInfo(). -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Dear R-users, I use unlist of POSIX dates to extract the year, hour etc. With that I can search for files in my database which are in the form 'yyyymmddhh_synops.txt' However, I get stucked during midnight where unlist just gives NA's. The script is given below; the problem accurs at acc.period[16] (midnight). However when I write out the character, unlist works well. But as.character(acc.period[16]) is not the solution.... > dates=seq(as.Date("2006-03-01"), as.Date("2006-11-01"), "days") > i=1 > begin=paste(dates[i]-1,"09:00:00") > end=paste(dates[i],"08:00:00") > acc.period=seq(as.POSIXct(begin),as.POSIXct(end),"hour") > > unlist(strptime(acc.period[15],format="%Y-%m-%d %H:%M:%S")) sec min hour mday mon year wday yday isdst 0 0 23 28 1 106 2 58 0 > unlist(strptime(acc.period[16],format="%Y-%m-%d %H:%M:%S")) sec min hour mday mon year wday yday isdst NA NA NA NA NA NA NA NA -1 > unclass(strptime(acc.period[16],format="%Y-%m-%d %H:%M:%S")) $sec [1] NA $min [1] NA $hour [1] NA $mday [1] NA $mon [1] NA $year [1] NA $wday [1] NA $yday [1] NA $isdst [1] -1 > > a="2006-03-01 00:00:00" > unlist(strptime(a,format="%Y-%m-%d %H:%M:%S")) sec min hour mday mon year wday yday isdst 0 0 0 1 2 106 3 59 0 > > sessionInfo() R version 2.4.0 (2006-10-03) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] "methods" "stats" "graphics" "grDevices" "utils" "datasets" [7] "base" Thanks in advance! Hanneke -- --------------------------------------------- ir J.M. (Hanneke) Schuurmans PhD student Hydrology Department of Physical Geography Faculty of Geosciences - Universiteit Utrecht P.O. Box 80115 3508 TC Utrecht T +31 (0)30 2532988 F +31 (0)30 2531145 W www.geo.uu.nl/staff/schuurmans