[Rd] forwarded: bug (?) in cut.POSIXt with "breaks"=integer
Ben Bolker
bolker at ufl.edu
Thu Oct 15 19:10:45 CEST 2009
From: Vitalie S. <vitosmail <at> rambler.ru>
Subject: Bug in cut.POSIXt
Newsgroups: gmane.comp.lang.r.general
Date: 2009-10-15 15:47:48 GMT (1 hour and 29 minutes ago)
Hello Everyone,
Before reporting decided to post here first:
tt <- structure(c(1254238817, 1254238859, 1254238969, 1254239080), class =
c("POSIXt",
"POSIXct"),
tzone = "")
cut.POSIXt(tt, 2)
#Error in `levels<-.factor`(`*tmp*`, value = character(0)) :
# number of levels differs
cut.POSIXt(tt, 2, labels=c("a1", "a2"))
#[1] a1 a1 a2 a2
#Levels: a1 a2
cut(tt, "2 mins")
#[1] 2009-09-29 17:40:00 2009-09-29 17:40:00 2009-09-29 17:42:00
2009-09-29 17:44:00
#Levels: 2009-09-29 17:40:00 2009-09-29 17:42:00 2009-09-29 17:44:00
> sessionInfo()
R version 2.9.2 Patched (2009-09-24 r50069)
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] stats graphics utils datasets grDevices methods base
>
Vitalie.
======================
I would agree that this is a bug ... this patch gets rid of the error,
but leaves the labels very ugly -- given enough hours I might be able to
figure out how to make the labels nice, but someone else can probably do
it quicker (see comments in code below)
It would probably also be worth adding something like
cut(Dates,2)
around line 5067 of reg-tests-1.R
--- datetime.R 2009-10-15 13:01:15.000000000 -0400
***************
*** 764,770 ****
}
} else stop("invalid specification of 'breaks'")
res <- cut(unclass(x), unclass(breaks), labels = labels, right =
right, ...)
! if(is.null(labels)) levels(res) <-
as.character(breaks[-length(breaks)])
res
}
--- 764,782 ----
}
} else stop("invalid specification of 'breaks'")
res <- cut(unclass(x), unclass(breaks), labels = labels, right =
right, ...)
! if(is.null(labels)) {
! if (is.numeric(breaks) && length(breaks) == 1L)
! levels(res) <- as.character(breaks[-length(breaks)])
! } else {
! ## ?? what should happen here?
! ## this version simply leaves the break values
! ## as numeric (and very ugly)
! ## I don't know how to safely convert the breakpoints
! ## back to a character format (e.g.
! ## levels(res) = [1970-01-01 00:00:00,1970-01-01 12:00:00)
! ## instead of [18000,61200)
! }
! }
res
}
--
Ben Bolker
Associate professor, Biology Dep't, Univ. of Florida
bolker at ufl.edu / www.zoology.ufl.edu/bolker
GPG key: www.zoology.ufl.edu/bolker/benbolker-publickey.asc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 261 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20091015/ebc04172/attachment.bin>
More information about the R-devel
mailing list