Skip to content
Prev 70780 / 398526 Next

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

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