[R] formatting a result table (number of digits)

David Winsemius dwinsemius at comcast.net
Fri Apr 9 00:52:32 CEST 2010


On Apr 8, 2010, at 6:20 PM, Esmail wrote:

> Hello,
>
> Is there an easy way to format the output of a result table that R
> generates from a regression?  I like the table, but would like to
> limit the number of decimal points in the entries if possible.
>
> For instance I would like only 3 digits of precision for the Value,
> Std.Error. (And if it would be easy to get rid of scientific notation,
> that would be good to know too). So ideally keep the table/headers  
> etc,
> but chance the entries.
>
> I've looked at format and print without much success.
> I'm using  R 2.10.1 in a Linux environment.
>
> Thanks,
> Esmail
>
>
> Below's an example of generating the table I am trying to format:

Well, that's not a reproducible example. At any rate, use print with  
the digits argument:

 > require(nlme)
Loading required package: nlme
 > ?lme
 > fm1 <- lme(distance ~ age, data = Orthodont) # random is ~ age
 > s <- summary(fm1)
 > s$tTable
                  Value  Std.Error DF   t-value      p-value
(Intercept) 16.7611111 0.77524609 80 21.620375 3.737321e-35
age          0.6601852 0.07125325 80  9.265334 2.645937e-14

 > print(s$tTable, digits=3)
             Value Std.Error DF t-value  p-value
(Intercept) 16.76    0.7752 80   21.62 3.74e-35
age          0.66    0.0713 80    9.27 2.65e-14

Y'er not going to be able to get rid of the scientific notation when  
the p-values are in the range of e-14.

-- 
David.

>
> > load('data.rda')
> > library(nlme)
> > ic <- lme(Ind_Cntrbn ~ D_Clb_Pbl+D_Club+Round 
> + 
> Ind_cntr_1 
> +GR_cntr_1+D_Success_1+IndEarngs_1+D_Unfair_cntr_1+D_1st10rnds 
> +D_Female+D_econ_gov+D_mjr_social+D_frshmn+D_junior+D_senior 
> +UrbanArea+ParentEducation+Empathy+Lcs_Cntrl_Intn+Trust, random=~1| 
> Group, data=Dataset)
> > s=summary(ic)
> > t=s$tTable
> > t
>                       Value  Std.Error   DF     t-value      p-value
> (Intercept)      5.683020304 0.78867419 2237  7.20578963 7.853134e-13
> D_Clb_Pbl        0.193187682 0.25494452   22  0.75776363 4.566332e-01
> D_Club           0.112745107 0.09636280 2237  1.17000650 2.421230e-01
> Round           -0.096400805 0.01812222 2237 -5.31948107 1.144272e-07
> Ind_cntr_1       0.340706093 0.04002901 2237  8.51147920 3.097981e-17
> GR_cntr_1        0.033215293 0.01271829 2237  2.61161545 9.071799e-03
> D_Success_1      2.210964800 0.38904872 2237  5.68300241 1.496038e-08
> IndEarngs_1     -0.277758214 0.03903289 2237 -7.11600506 1.489839e-12
> D_Unfair_cntr_1 -0.535979858 0.18280685 2237 -2.93194624 3.402644e-03
> D_1st10rnds     -0.479775417 0.19375663 2237 -2.47617547 1.335331e-02
> D_Female         0.076666269 0.12354518 2237  0.62055250 5.349573e-01
> D_econ_gov      -0.282679230 0.12023002 2237 -2.35115350 1.880165e-02
> D_mjr_social     0.149134543 0.12572505 2237  1.18619595 2.356709e-01
> D_frshmn        -0.149157208 0.20609463 2237 -0.72373166 4.693062e-01
> D_junior        -0.112917886 0.17455488 2237 -0.64689045 5.177692e-01
> D_senior        -0.107570461 0.15088326 2237 -0.71293835 4.759583e-01
> UrbanArea       -0.364410559 0.11988827 2237 -3.03958489 2.396486e-03
> ParentEducation  0.098237171 0.05350248 2237  1.83612365 6.647201e-02
> Empathy          0.042232476 0.08248236 2237  0.51201825 6.086888e-01
> Lcs_Cntrl_Intn   0.132131306 0.08841098 2237  1.49451240 1.351828e-01
> Trust           -0.003872427 0.08468412 2237 -0.04572789 9.635312e-01
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list