Skip to content

Why does "summary" show number of NAs as non-integer?

3 messages · Earl F. Glynn, Bert Gunter, Marc Schwartz

#
Example:
Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's
  7.771  24.850  43.040  43.940  63.540  83.830   2.000

Why isn't the number of NA's just "2" instead of the "2.000" shown above?

efg
#
summary() is an S3 generic that for your vector dispatches
summary.default(). The output of summary default has class "table" and so
calls print.table (print is another S3 generic). Look at the code of
print.table() to see how it formats the output.

-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA
 
"The business of the statistician is to catalyze the scientific learning
process."  - George E. P. Box
#
On Tue, 2005-05-31 at 17:14 -0500, Earl F. Glynn wrote:
This is actually related to the thread on formatting numbers.

In reviewing the Detail section of ?print.default:

"The same number of decimal places is used throughout a vector, This
means that digits specifies the minimum number of significant digits to
be used, and that at least one entry will be printed with that minimum
number."

'digits' in the above is the digits argument to print.default(). In this
case, it defaults to options("digits"), which is 7.

In the above output from summary, you will note that all of the output
has three digits after the decimal place.

Thus:
[1] 2
[1] 2 3
[1] 2.0 3.5
[1] 2.00 3.57
[1] 2.000 3.579


Note how the output format of "2" varies depending upon how many decimal
places I use in the second element. 

This goes to the need to use other functions where there is a need to
exert greater control over how numeric output can be formatted and
aligned using formatC() and/or sprintf().

For example:
[1] "0 decimal places: 2    3 decimal places: 3.579"


See ?sprintf and ?formatC for more information.

HTH,

Marc Schwartz