Prof Brian Ripley <[EMAIL PROTECTED]> writes:

> > tt<-table(zz%/%10)
> > n <- names(tt)
> > names(tt) <- paste(n,0,"-",n,9,sep="")
> > tt
> > data.frame(count=c(tt))
> > 
> > Beware that empty groups are silently zapped, though.
> 
> FWIW, table(factor(zz%/%10, levels=0:9))  avoids that

I knew, but then you'd basically be back to using cut. Your fix will
lose if there are any 107-year olds, by the way. It will also include
a number of empty groups below the range of data, which might not be
what you want.

Here's a first stab at a more general solution:

sz <- 10 
g <- zz %/% sz
lv <- min(g):max(g)
lb <- paste(lv * sz, "-", lv * sz + sz - 1, sep="")
f <- factor(g,levels=lv,labels=lb)
(tt <- table(f))
data.frame(count=c(tt))


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED])             FAX: (+45) 35327907

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to