Re: [R] ?bug? strange factors produced by chron

From: Petr Pikal <petr.pikal_at_precheza.cz>
Date: Mon 13 Feb 2006 - 22:31:41 EST

Thank you very much.

On 13 Feb 2006 at 10:54, Prof Brian Ripley wrote:

Date sent:      	Mon, 13 Feb 2006 10:54:21 +0000 (GMT)
From:           	Prof Brian Ripley <ripley@stats.ox.ac.uk>
To:             	Petr Pikal <petr.pikal@precheza.cz>
Copies to:      	r-help@stat.math.ethz.ch
Subject:        	Re: [R] ?bug? strange factors produced by chron

> 1) The obvious test is via is.factor(), and you have not used that.

I used it with TRUE result but did not use in my post (mea culpa)
> is.factor(kvartaly)

[1] TRUE
> 2) Your example works for me, so what versions of R and chron is this?

Package: chron
Version: 2.3-1
R 2.2.1 and W2000

but problem is probably in interaction (see below)
>
> 3) Here's my guess. split is using the C-level test isFactor. That
> tests that the factor is of type integer, so please try
>
> > typeof(kvartaly)

 > typeof(kvartaly)
 [1] "double"  

Problem is probably not in chron but in interaction, which silently transfers factor type to double

> typeof(factor(letters[1:2]))
[1] "integer"

> typeof(interaction(factor(letters[1:2]), factor(letters[3:4])))
[1] "double"
>

>
> I suspect you will get "double" and not "integer", and if so you can
> fix this by
>
> storage.mode(kvartaly) <- "integer"

Thanks, it works.

>
> So here's an example which will fail
>
> > fac2 <- rep(c(1,2,3), each=5)
> > attr(fac2, "levels") <- as.character(1:3)
> > oldClass(fac2) <- "factor"
> > is.factor(fac2)
> [1] TRUE
> > split(rnorm(15), fac2)
> Error in split(x, f) : second argument must be a factor
>
> I think it is an error that the R-level and C-level tests for
> is.factor() are different.

<snip>

> > vec1<-as.Date(Sys.time())
>
> Why not Sys.Date() ?

I remembered only Sys.time when writing my mail.

>

<snip>

Thank you again.

Best regards.
PetrPetr Pikal
petr.pikal@precheza.cz



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Feb 13 22:43:08 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:29 EST