Hi, Does anybody know why get I this kind of strange situation: Browse[2]> hcEnd [1] "2009-03-29 06:30:00" Browse[2]> class(hcEnd) [1] "POSIXlt" "POSIXt" Browse[2]> is.na(hcEnd) [1] TRUE This issue is the source of my all issues in my program, Thanks for your help -- View this message in context: http://r.789695.n4.nabble.com/strange-behaviour-of-POSIXlt-POSIXt-object-tp4418115p4418115.html Sent from the R help mailing list archive at Nabble.com.
R. Michael Weylandt <michael.weylandt@gmail.com>
2012-Feb-24 18:28 UTC
[R] strange behaviour of "POSIXlt" "POSIXt" object
Can you dput(hcEnd) and give a snippet of the code that generates it? Michael On Feb 24, 2012, at 12:57 PM, ikuzar <razuki at hotmail.fr> wrote:> Hi, > Does anybody know why get I this kind of strange situation: > > Browse[2]> hcEnd > [1] "2009-03-29 06:30:00" > Browse[2]> class(hcEnd) > [1] "POSIXlt" "POSIXt" > Browse[2]> is.na(hcEnd) > [1] TRUE > > This issue is the source of my all issues in my program, > > Thanks for your help > > -- > View this message in context: http://r.789695.n4.nabble.com/strange-behaviour-of-POSIXlt-POSIXt-object-tp4418115p4418115.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.
> Does anybody know why get I this kind of strange situation: > > Browse[2]> hcEnd > [1] "2009-03-29 06:30:00" > Browse[2]> class(hcEnd) > [1] "POSIXlt" "POSIXt" > Browse[2]> is.na(hcEnd) > [1] TRUEpp<-as.POSIXlt("2009-03-29 06:30:00") pp [1] "2009-03-29 06:30:00" class(pp) [1] "POSIXlt" "POSIXt" is.na(pp) [1] FALSE So we can't repeat your example. -- Curt Seeliger, Data Ranger Raytheon Information Services - Contractor to ORD seeliger.curt@epa.gov 541/754-4638 [[alternative HTML version deleted]]
What version of R are you using. Here is the results with 2.14.1 under Windows:> x <- as.POSIXlt("2009-03-29 06:30:00") > > x[1] "2009-03-29 06:30:00"> class(x)[1] "POSIXlt" "POSIXt"> is.na(x)[1] FALSE>On Fri, Feb 24, 2012 at 12:57 PM, ikuzar <razuki@hotmail.fr> wrote:> Hi, > Does anybody know why get I this kind of strange situation: > > Browse[2]> hcEnd > [1] "2009-03-29 06:30:00" > Browse[2]> class(hcEnd) > [1] "POSIXlt" "POSIXt" > Browse[2]> is.na(hcEnd) > [1] TRUE > > This issue is the source of my all issues in my program, > > Thanks for your help > > -- > View this message in context: > http://r.789695.n4.nabble.com/strange-behaviour-of-POSIXlt-POSIXt-object-tp4418115p4418115.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. [[alternative HTML version deleted]]
Hi, I do not know what part of my code should I post here (I use large size of data, the loop "for" contains many lines). The situation is difficult to post here, but I hope these lines would be useful for help: hcEndDateTmp = userDateStart if((hcStartTime<="23:59") & (hcEndTime >= "00:00")){ hcEndDateTmp$mday = userDateStart$mday + 1 } hcEndDate = strftime(hcEndDateTmp, "%Y-%m-%d") hcStart = "" hcEnd = as.POSIXlt(paste(hcEndDate, hcEndTime)) for(rowNum in 1:nbJour){ ... hcStart = as.POSIXlt(ecs$startAt[[rowNum]]) ecsInterval2 datePower[(datePower$DateTime>=hcStart)&(datePower$DateTime<=hcEnd), ] ... hcEnd$mday = hcEnd$mday + 1 cat("DEBUG: rowNum=", rowNum, "is.na(hcEnd)=", is.na(hcEnd), "\n") } the two last lines are very important. It yields: DEBUG: rowNum= 1 is.na(hcEnd)= FALSE DEBUG: rowNum= 2 is.na(hcEnd)= FALSE DEBUG: rowNum= 3 is.na(hcEnd)= FALSE DEBUG: rowNum= 4 is.na(hcEnd)= FALSE DEBUG: rowNum= 5 is.na(hcEnd)= FALSE DEBUG: rowNum= 6 is.na(hcEnd)= FALSE DEBUG: rowNum= 7 is.na(hcEnd)= TRUE Browse[1]> hcEnd [1] "2009-03-29 06:30:00" Browse[1]> class(hcEnd) [1] "POSIXlt" "POSIXt" So, At the end of 7th iteration, hcEnd becomes NA (I guess because of hcEnd$mday = hcEnd$mday + 1 ?!?). But It remains strange because the class of hcEnd is here "POSIXlt" "POSIXt" (it should be "logical".!! Am I wrong???) Here is the version of R: platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 13.2 year 2011 month 09 day 30 svn rev 57111 language R version.string R version 2.13.2 (2011-09-30) thanks for your help -- View this message in context: http://r.789695.n4.nabble.com/strange-behaviour-of-POSIXlt-POSIXt-object-tp4418115p4424214.html Sent from the R help mailing list archive at Nabble.com.
is.na(POSIXltObject) can behave oddly if you manipulate the fields of the POSIXlt object directly so as to cause illegal combinations of values. E.g., the 35th of February, 2009, is not considered an NA but the 36th and above are: > z <- as.POSIXlt("2009-02-25 06:30:00") > for(i in 1:20){ z$mday <- z$mday + 1L ; cat(is.na(z), ": ");print(z)} FALSE : [1] "2009-02-26 06:30:00" FALSE : [1] "2009-02-27 06:30:00" FALSE : [1] "2009-02-28 06:30:00" FALSE : [1] "2009-03-01 06:30:00" FALSE : [1] "2009-03-02 06:30:00" FALSE : [1] "2009-03-03 06:30:00" FALSE : [1] "2009-03-04 06:30:00" FALSE : [1] "2009-03-05 06:30:00" FALSE : [1] "2009-03-06 06:30:00" FALSE : [1] "2009-03-07 06:30:00" TRUE : [1] "2009-03-08 06:30:00" TRUE : [1] "2009-03-09 06:30:00" TRUE : [1] "2009-03-10 06:30:00" TRUE : [1] "2009-03-11 06:30:00" TRUE : [1] "2009-03-12 06:30:00" TRUE : [1] "2009-03-13 06:30:00" TRUE : [1] "2009-03-14 06:30:00" TRUE : [1] "2009-03-15 06:30:00" TRUE : [1] "2009-03-16 06:30:00" TRUE : [1] "2009-03-17 06:30:00" The print routine does not seem to consult is.na(). Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of ikuzar > Sent: Monday, February 27, 2012 2:41 AM > To: r-help at r-project.org > Subject: Re: [R] strange behaviour of "POSIXlt" "POSIXt" object > > Hi, > > I do not know what part of my code should I post here (I use large size of > data, the loop "for" contains many lines). The situation is difficult to > post here, but I hope these lines would be useful for help: > > hcEndDateTmp = userDateStart > if((hcStartTime<="23:59") & (hcEndTime >= "00:00")){ > hcEndDateTmp$mday = userDateStart$mday + 1 > } > hcEndDate = strftime(hcEndDateTmp, "%Y-%m-%d") > hcStart = "" > hcEnd = as.POSIXlt(paste(hcEndDate, hcEndTime)) > > for(rowNum in 1:nbJour){ > ... > hcStart = as.POSIXlt(ecs$startAt[[rowNum]]) > ecsInterval2 > datePower[(datePower$DateTime>=hcStart)&(datePower$DateTime<=hcEnd), ] > ... > hcEnd$mday = hcEnd$mday + 1 > cat("DEBUG: rowNum=", rowNum, "is.na(hcEnd)=", is.na(hcEnd), "\n") > } > > the two last lines are very important. It yields: > > DEBUG: rowNum= 1 is.na(hcEnd)= FALSE > DEBUG: rowNum= 2 is.na(hcEnd)= FALSE > DEBUG: rowNum= 3 is.na(hcEnd)= FALSE > DEBUG: rowNum= 4 is.na(hcEnd)= FALSE > DEBUG: rowNum= 5 is.na(hcEnd)= FALSE > DEBUG: rowNum= 6 is.na(hcEnd)= FALSE > DEBUG: rowNum= 7 is.na(hcEnd)= TRUE > > Browse[1]> hcEnd > [1] "2009-03-29 06:30:00" > Browse[1]> class(hcEnd) > [1] "POSIXlt" "POSIXt" > > So, At the end of 7th iteration, hcEnd becomes NA (I guess because of > hcEnd$mday = hcEnd$mday + 1 ?!?). But It remains strange because the class > of hcEnd is here "POSIXlt" "POSIXt" (it should be "logical".!! Am I > wrong???) > > Here is the version of R: > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major 2 > minor 13.2 > year 2011 > month 09 > day 30 > svn rev 57111 > language R > version.string R version 2.13.2 (2011-09-30) > > thanks for your help > > -- > View this message in context: http://r.789695.n4.nabble.com/strange-behaviour-of-POSIXlt-POSIXt- > object-tp4418115p4424214.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.
So, how is the correct way to increment the day ? -- View this message in context: http://r.789695.n4.nabble.com/strange-behaviour-of-POSIXlt-POSIXt-object-tp4418115p4425206.html Sent from the R help mailing list archive at Nabble.com.