[R] format as percentage

David Winsemius dwinsemius at comcast.net
Wed Nov 10 14:03:02 CET 2010


On Nov 10, 2010, at 5:13 AM, Jim Lemon wrote:

> On 11/10/2010 07:55 PM, Santosh Srinivas wrote:
>> Basic question ... checked the help page but the only answer was to  
>> use
>> paste!
>> Is there any way to format as %?

 > sprintf("%1.0f %%",10)
[1] "10 %"
 > sprintf("%1.0f%%",10)
[1] "10%"


>>
>>> degree = c(0.20,0.5)
>>> degree
>> [1] 0.2 0.5
>>> print(degree)
>> [1] 0.2 0.5
>>
> Hi Santosh,
> If you want to scale proportions to percentages, you probably want  
> this:
>
> paste(100*degree,"%")
>
> You may also have to look at rounding the result to avoid those awful
>
> 27.29387163%
>
> outcomes.
>
> Jim



More information about the R-help mailing list