From maechler at stat.math.ethz.ch  Tue Mar 19 17:30:45 2013
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Tue, 19 Mar 2013 17:30:45 +0100
Subject: [Rd] numerics from a factor
In-Reply-To: <51445FB7.9090503@bht-berlin.de>
References: <mailman.27.1363431608.4225.r-devel@r-project.org>
	<51445FB7.9090503@bht-berlin.de>
Message-ID: <20808.37557.715432.547904@stat.math.ethz.ch>

>>>>> Ulrike Gr?mping <groemping at bht-berlin.de>
>>>>>     on Sat, 16 Mar 2013 13:04:07 +0100 writes:

    > Hi Terry, you can use type.convert instead of as.numeric
    > for numbers with decimals:

    > type.convert(levels(factor(1:6/2)),  dec=unlist(options("OutDec")))

    > Best, Ulrike

a late and minor remark: If you use the above, a slightly more expressive
preferred way is 

  type.convert(levels(factor(1:6/2)),  dec = getOption("OutDec"))

Martin


    > Am 16.03.2013 12:00, schrieb r-devel-request at r-project.org:

   [...]

    >> A problem has been pointed out by a French user of the survival package and I'm looking
    >> for a pointer.
    >> 
    >> > options(OutDec= ",")
    >> > fit <- survfit(Surv(1:6 /2) ~ 1)
    >> > fit$time
    >> [1] NA  1 NA  2 NA  3
    >> 
    >> A year or two ago some test cases that broke survfit were presented to me. The heart of
    >> the problem was numbers that were almost identical, where table(x) and unique(x) gave
    >> different counts of distinct values.
    >> The solution was to use "ftime <- factor(time)" at the top of the code, and do all the
    >> calulations using the integer levels of the factor as the unique time points.  At the very
    >> end the numeric component "time" of the result is created using
    >> as.numeric(levels(ftime)).  It's this last line that breaks.
    >> 
    >> I could set the OutDec option within survfit and reset when I leave using on.exit.  Any
    >> other simple solutions?  Any other ways I could get caught by this issue?
    >> 
    >> Terry Therneau



[Rd] numerics from a factor
Martin Maechler