[R] number of decimal

Ivan Calandra ivan.calandra at uni-hamburg.de
Thu Jan 28 17:07:40 CET 2010


I guess the easiest solution for me would therefore be to set 
options(digits) to a high number, and then round down if I need to!
Thanks you both for your input!
Ivan


Le 1/28/2010 17:02, Peter Ehlers a écrit :
> Looks like I didn't read your post carefully enough.
> If you want some sort of global option to set the
> display of numbers from any operation performed by R
> then that's not likely to be possible without
> capturing all output and formatting it yourself.
> As the saying goes 'good luck with that'.
>
> Note that options(digits=..) won't give you the
> requested number of digits in all parts of, say,
> print(t.test(x,y)).
>
>  -Peter Ehlers
>
> Peter Ehlers wrote:
>> 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.
>>>>>
>>>>>
>>>
>>>
>>
>



More information about the R-help mailing list