[R] ?bug? strange factors produced by chron

From: Petr Pikal <petr.pikal_at_precheza.cz>
Date: Mon 13 Feb 2006 - 20:59:16 EST


Hallo all

Please help me. I am lost and do not know what is the problem. I have a factor called kvartaly.

> attributes(kvartaly)

$levels
[1] "1Q.04" "2Q.04" "3Q.04" "4Q.04" "1Q.05" "2Q.05" "3Q.05" "4Q.05" $class
[1] "factor"
> mode(kvartaly)

[1] "numeric"
> str(kvartaly)

 Factor w/ 8 levels "1Q.04","2Q.04",..: 1 1 1 1 1 1 1 1 1 1 ...
>

but if I call split it throws an error

> split(rnorm(731),kvartaly)

Error in split(x, f) : second argument must be a factor

so I tried to make a test example which works if I try to construct factor manually but fails if I use chron

vec<-c("1Q.04", "1Q.05", "1Q.06")
fac<-as.factor(rep(vec,c(5,5,5)))

split(rnorm(15),fac)
$"1Q.04"
[1] 1.9803999 -0.3672215 -1.0441346 0.5697196 -0.1350546

$"1Q.05"
[1] 2.40161776 -0.03924000 0.68973936 0.02800216 -0.74327321

$"1Q.06"
[1] 0.1887923 -1.8049586 1.4655549 0.1532533 2.1726117

vec1<-as.Date(Sys.time())
vec1<-c(vec1, vec1-100, vec1-300)
vec1<-rep(vec1,c(5,5,5))
fac1<-interaction(quarters(as.chron(as.POSIXct(vec1))), 
format(vec1,"%y"))
> split(rnorm(15),fac1)
Error in split(x, f) : second argument must be a factor
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Why split does not accept fac1 if according to all tests it **is** a factor?

Thank you
Petr

Petr 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 21:07:37 2006

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