[R] Failure to aggregate

Petr PIKAL petr.pikal at precheza.cz
Thu Sep 9 17:02:53 CEST 2010


Hi

you has to provide some more info about x e.g. str(x)

x<-data.frame(price=1, h=Sys.time())



r-help-bounces at r-project.org napsal dne 08.09.2010 10:18:52:

> 
> Mnay thanks fr suggestions. I am afraid this is one tough daatframe...
> 
> > t = sqldf("select h, count(*) from x group by h")
> Error in sqliteExecStatement(con, statement, bind.data) : 
>   RS-DBI driver: (error in statement: no such table: x)
> In addition: Warning message:
> In value[[3L]](cond) : RAW() can only be applied to a 'raw', not a 
'double'

did not test

> 
> > t = aggregate(x["price"], by = x["h"], FUN = NROW) 
> Error in sort.list(y) : 'x' must be atomic for 'sort.list'
> Have you called 'sort' on a list?

works
 aggregate(x["price"], by = x["h"], FUN = NROW) 
                    h price
1 2010-09-09 16:58:04     1


> 
> > t = aggregate(x["price"], by = x["h"], FUN = length) 
> Error in sort.list(y) : 'x' must be atomic for 'sort.list'
> Have you called 'sort' on a list?

works

aggregate(x["price"], by = x["h"], FUN = length)
                    h price
1 2010-09-09 16:58:04     1


> 
> > t = tapply(x$price, by = x$h, FUN = length) 
> Error in is.list(INDEX) : 'INDEX' is missing

works
use INDEX instead of by

tapply(x$price, by = list(x$h), FUN = length)
Error in is.list(INDEX) : 'INDEX' is missing
tapply(x$price, x$h, FUN = length)
2010-09-09 16:58:04 
                  1

Regards
Petr

> 
> > class(x)
> [1] "data.frame"
> > class(x$h)
> [1] "POSIXt"  "POSIXlt"
> > class(x$price)
> [1] "integer"
> 
> -- 
> View this message in context: http://r.789695.n4.nabble.com/Failure-to-
> aggregate-tp2528613p2530963.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list