Skip to content
Prev 313672 / 398502 Next

format.pval () and printCoefmat ()

Hi Arun,

Thank you so much for further clarifications and help.

Pradip

Pradip K. Muhuri, PhD
Statistician
Substance Abuse & Mental Health Services Administration
The Center for Behavioral Health Statistics and Quality
Division of Population Surveys
1 Choke Cherry Road, Room 2-1071
Rockville, MD 20857

Tel: 240-276-1070
Fax: 240-276-1260
e-mail: Pradip.Muhuri at samhsa.hhs.gov

The Center for Behavioral Health Statistics and Quality your feedback.  Please click on the following link to complete a brief customer survey:   http://cbhsqsurvey.samhsa.gov


-----Original Message-----
From: arun [mailto:smartpink111 at yahoo.com]
Sent: Saturday, December 15, 2012 11:04 AM
To: Muhuri, Pradip (SAMHSA/CBHSQ)
Cc: R help; David Winsemius
Subject: Re: [R] format.pval () and printCoefmat ()

Hi Pradip,

It this is just formatting issue, it is possible to do that with ?formatC() or ?sprintf(), but it may change those variables from numeric to character.
One possibilty from `res`:
res<-data.frame(dat1[,1:2],read.table(text=Lines2,header=TRUE))

varsNum<-sapply(res,is.numeric)
res[varsNum]<-lapply(res[varsNum],round,digits=3)
#Here, the numeric columns with digits<3 are not changed, but the ones with >3 were all changed to digits3.

As I mentioned, sprintf() changes the number of digits
 as.data.frame(do.call(cbind,lapply(res[varsNum],function(x) sprintf("%.3f",x))))
#   mean_level1 mean_level2 rel_diff p_mean cohens_d
#1       18.700      11.910    0.574  0.000    0.175
#2       18.700      14.460    0.297  0.000    0.110
#3       18.700      13.540    0.384  0.000    0.134

A.K.





----- Original Message -----
From: "Muhuri, Pradip (SAMHSA/CBHSQ)" <Pradip.Muhuri at samhsa.hhs.gov>
To: arun <smartpink111 at yahoo.com>
Cc: R help <r-help at r-project.org>; David Winsemius <dwinsemius at comcast.net>
Sent: Saturday, December 15, 2012 10:12 AM
Subject: RE: [R] format.pval () and printCoefmat ()

Dear Arun and David,

I am so grateful to you for all your help with the code.  Thanks and regards, Pradip


Arun - All this  is very helpful.  In general, I can follow the code. I only have the following questions:

What changes in the code would be required to have 3 places after decimal for all numeric variables in the "res" data frame?

Thanks,

Pradip



####### below is the display of the data from Lines1, Lines2, and res
Lines1
1    mean_level1 mean_level2 rel_diff p_mean cohens_d
2 1       18.744      11.911    0.574   0.00    0.175
3 2       18.744      14.455    0.297   0.00    0.110
4 3       18.744      13.540    0.384   0.00    0.133
5 4       18.744       6.002    2.123   0.00    0.333
6 5       18.744       5.834    2.213   0.00    0.349
Lines2
1    mean_level1 mean_level2 rel_diff p_mean cohens_d
2 1       18.744      11.911    0.574   0.00    0.175
3 2       18.744      14.455    0.297   0.00    0.110
4 3       18.744      13.540    0.384   0.00    0.133
5 4       18.744       6.002    2.123   0.00    0.333
6 5       18.744       5.834    2.213   0.00    0.349
contrast_level1 contrast_level2 mean_level1 mean_level2 rel_diff p_mean cohens_d
1              wh            2+hi        18.7       11.91    0.574      0    0.175
2              wh            2+rc        18.7       14.46    0.297      0    0.110
3              wh            aian        18.7       13.54    0.384      0    0.133
4              wh            asan        18.7        6.00    2.123      0    0.333
5              wh            blck        18.7        5.83    2.213      0    0.349
6              wh            csam        18.7        7.93    1.363      0    0.279