[R] cut.POSIXt misconception/feature/bug?

Petr PIKAL petr.pikal at precheza.cz
Wed Mar 10 10:01:23 CET 2010


Dear all
recently I tried to split vector of dates according to some particular 
date to 2 (more) chunks, but I was not able to perform correct setting.

When I want split to 3 chunks it partially works however from help page I 
supposed to get result without NA.

Details:

     Using both ‘right = TRUE’ and ‘include.lowest = TRUE’ will
     include both ends of the range of dates.

dat <- seq(c(ISOdate(2000,3,20)), by = "day", length.out = 60)
br<-dat[c(23, 42)]
head(cut(dat, breaks=br, right=T, include.lowest=T))

[1] <NA> <NA> <NA> <NA> <NA> <NA>
Levels: 2000-04-11 14:00:00

which apparently is not output I would like to have.

When trying to split to 2 chunks there is a strange error

br<-dat[42]
cut(dat, breaks=br, right=T, include.lowest=T)
Error in cut.default(unclass(x), unclass(breaks), labels = labels, right = 
right,  :  cannot allocate vector of length 955454401

I traced it back to 

Browse[5]> nb
[1] 955454401
^^^^^^^^^^^^^^^^^^^^^^
Browse[5]> 
debug: NULL
Browse[5]> 
debug: breaks <- seq.int(rx[1L] - dx/1000, rx[2L] + dx/1000, length.out = 
nb)
Browse[5]> 
Error in cut.default(unclass(x), unclass(breaks), labels = labels, right = 
right,  : 
  cannot allocate vector of length 955454401

which is probably not correct.

Can somebody help me to the right track?


> version
               _  
platform       i386-pc-mingw32  
arch           i386  
os             mingw32  
system         i386, mingw32  
status         Under development (unstable)  
major          2  
minor          11.0  
year           2010  
month          03  
day            09  
svn rev        51229  
language       R  
version.string R version 2.11.0 Under development (unstable) (2010-03-09 
r51229)

Regards
Petr



More information about the R-help mailing list