[R] cut POSIX results in NA - bug?

Petr Pikal petr.pikal at precheza.cz
Wed Nov 3 11:03:42 CET 2004


Dear all

I try to make hourly average by cut() function, which almost works 
as *I* expected. What puzled me is that if there is only one item at 
the end of your data it results in NA.

Example will explain what I mean

datum<-seq(ISOdate(2004,8,31), ISOdate(2004,9,1), "min")

cut(datum[1370:1381],"hour", labels=F)
 [1]  1  1  1  1  1  1  1  1  1  1  1 NA

cut(datum[1370:1382],"hour", labels=F)
 [1] 1 1 1 1 1 1 1 1 1 1 1 2 2

I do not understand why the last item in first call is NA. I found it 
only when there was a switch from DST to standard time as it 
coused a trouble in one of my functions and I found there is NA 
value where I did not expected it. 

I can make some workaround but can you please explain me why 
first call results in NA value at the end of a vector and if it is 
*intended* behaviour. If yes I can count with it in improvement of 
my function(s), if not I can make some temporary workaround.

Thank you.

Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list