[Rd] round, unique and factor

From: Terry Therneau <therneau_at_mayo.edu>
Date: Mon, 21 Mar 2011 10:46:41 -0500


 Survfit had a bug in some prior releases due to the use of both unique(times) and table(times); I fixed it by rounding to 15 digits per the manual page for as.character. Yes, I should ferret out all the usages instead, but this was fast and it cured the user's problem.   The bug is back! A data set from a local colleage triggers it. I can send the rda file to anyone who wishes.

 The current code has

     digits <- floor((.Machine$double.digits) * 
                    logb(.Machine$double.base,10)) #base 10 digits
     Y[,1] <- signif(Y[,1], digits)

which gives 15 digits; should I subtract one more?   

Should the documentation change?

In the meantime I'm looking at the more permanent fix of turning time into a factor, then back at the very end. Because it is a bigger change the potential for breakage is higer, however.

Terry T.

tmt45% R --vanilla

R version 2.12.2 (2011-02-25)
Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0
Platform: x86_64-unknown-linux-gnu (64-bit)

> load('test.rda')
> ls()

[1] "temp2"
> temp2 <- round(temp2, 15)
> length(unique(temp2))

[1] 954
> length(table(temp2))

[1] 942
> .Machine$double.eps

[1] 2.220446e-16
> range(temp2)

[1] 0.0000 26.0397

Terry T.



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 21 Mar 2011 - 15:49:35 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 21 Mar 2011 - 16:20:36 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive