[R] Format printing with R

Steven T. Yen @tyen @end|ng |rom ntu@edu@tw
Tue Nov 22 11:24:15 CET 2022


Thanks to all. And yes, Ivan, round() did it:

 > dput(head(Mean))
c(afactfem = 0.310796641158209, afactblk = 0.188030178893171,
age = 45.3185794338312, nodiscfem = 0.506637018185968, discfem = 
0.493362981814032,
notradgrol = 0.702915000493879)
 > dput(head(Std.dev))
c(afactfem = 0.462819715443265, afactblk = 0.390736267472797,
age = 16.3136348021933, nodiscfem = 0.499955948049025, discfem = 
0.499955948049025,
notradgrol = 0.456974290933931)
 > round(cbind(Mean,Std.dev),2)[1:10,]
             Mean Std.dev
afactfem    0.31    0.46
afactblk    0.19    0.39
age        45.32   16.31
nodiscfem   0.51    0.50
discfem     0.49    0.50
notradgrol  0.70    0.46
tradgrol    0.30    0.46
nofemnopol  0.80    0.40
femnopol    0.20    0.40
nopreshurt  0.66    0.47

On 11/22/2022 3:08 PM, Ivan Krylov wrote:
> On Tue, 22 Nov 2022 08:15:57 +0800
> "Steven T. Yen" <styen using ntu.edu.tw> wrote:
>
>> Thanks to all, but no, signif() did not work:
> It worked, just didn't do what you wanted it to do. I think you want
> round(), not signif(). Some of your numbers (45.3185794) will be rounded
> to 4 significant digits and others (0.0969999) will be rounded to 1
> significant digit, but the number of decimal places will be 2.
>



More information about the R-help mailing list