[R] number of decimal
Peter Ehlers
ehlers at ucalgary.ca
Thu Jan 28 17:36:34 CET 2010
Ivan,
Now I'm no longer sure of just what you want. Are you concerned about
the *internal* handling of numbers by R or just about the *printing*
of numbers? As Marc has pointed out, internally R will use the full
precision that your input allows.
Perhaps you're using the F-value from the output of a
procedure like aov() as input to further analysis. If so,
don't use the printed value; pull the value out of the
object with something like
fm <- aov(y ~ x)
Fval <- summary(fm)[[1]][1,4]
But maybe this is not at all what you're after.
-Peter Ehlers
Ivan Calandra wrote:
> First things first: thanks for your help!
>
> I see where the confusion is. With formatC and sprintf, I have to store
> the numbers I want to change into x.
>
> I would like a way without applying a function on specific numbers
> because I can shorten the numbers that way, but it won't give me more
> decimals for a test for example.
> What I mean here is that if I have a F-value = 1.225, formatC won't give
> me the next 3 decimals, it will just add zeros.
> I need that because for some of my variables, the sample differ only at
> the 6th decimal (0.000005 vs 0.000006), and for other ones the order of
> magnitude is much higher (120.120225 vs 210.665331). So
> options(digits=6) cannot do the job as I would like. To make myself even
> clearer, notice that in my example, all numbers have 6 decimals, but a
> different number of digits.
>
> I hope I'm not bothering you with this question, but I believe that the
> functions you advised me will not do what I need.
> I really need something that will set up the number of decimals by
> default, before the numbers are created by any function.
> Does such an option even exist in R? Or is it that it doesn't make sense
> to have different numbers of digits? Would it be better to compare
> 0.000005 and 210.665? Therefore options(digits=6) would be enough.
>
> Regards,
> Ivan
>
> Le 1/28/2010 16:43, Peter Ehlers a écrit :
>> Ivan Calandra wrote:
>>> It looks to me that it does more or less the same as format().
>>>
>>> Maybe I didn't explain myself correctly then. I would like to set the
>>> number of decimal by default, for the whole R session, like I do with
>>> options(digits=6). Except that digits sets up the number of digits
>>> (including what is before the "."). I'm looking for some option that
>>> will let me set the number of digits AFTER the "."
>>>
>>> Example: I have 102.33556677 and 2.999555666
>>> If I set the number of decimal to 6, I should get: 102.335567 and
>>> 2.999556.
>>> And that for all numbers that will be in/output from R (read.table,
>>> write.table, statistic tests, etc)
>>>
>>> Or is it that I didn't understand everything about formatC() and
>>> sprintf()?
>> You didn't:
>>
>> formatC(x, digits=6, format="f")
>> [1] "102.335567" "2.999556"
>>
>> sprintf("%12.6f", x)
>> [1] " 102.335567" " 2.999556"
>>
>> -Peter Ehlers
>>
>> >
>>>
>>> Thanks again
>>> Ivan
>>>
>>> Le 1/28/2010 15:12, Peter Ehlers a écrit :
>>>> ?formatC
>>>> ?sprintf
>>>>
>>>> Ivan Calandra wrote:
>>>>> Hi everybody,
>>>>>
>>>>> I'm trying to set the number of decimals (i.e. the number of digits
>>>>> after the "."). I looked into options but I can only set the total
>>>>> number of digits, with options(digits=6). But since I have
>>>>> different variables with different order of magnitude, I would like
>>>>> that they're all displayed with the same number of decimals.
>>>>> I searched for it and found the format() function, with nsmall=6,
>>>>> but it is for a given vector. I would like to set it for the whole
>>>>> session, as with options.
>>>>>
>>>>> Can anyone help me?
>>>>> Thanks in advance
>>>>> Ivan
>>>>>
>>>>> ______________________________________________
>>>>> 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.
>>>>>
>>>>>
>>>
>>>
>>
>
>
--
Peter Ehlers
University of Calgary
More information about the R-help
mailing list