[R] "digits" doesn't work in format function

Gabor Grothendieck ggrothendieck at gmail.com
Thu Mar 22 16:08:58 CET 2007


Try

sprintf("%.2f", m)


On 3/22/07, Baoqiang Cao <bqcaomail at gmail.com> wrote:
> Dear All,
>
> I was trying to format a numeric vector (100*1) by using
> outd <- format(x=m, sci=F, digits=2)
>
> > outd[1:10]
>  [1] " 0.01787758" "-0.14760306" "-0.45806041" "-0.67858525" "-0.64591748"
>  [6] "-0.05918100" "-0.25632276" "-0.15980138" "-0.08359873" "-0.37866688"
> >m[1:10]
>  [1]  0.017878 -0.147603 -0.458060 -0.678585 -0.645917 -0.059181 -0.256323
>  [8] -0.159801 -0.083599 -0.378667
>
> I'm expecting something like, 0.02 -0.15 ...
>



More information about the R-help mailing list