Reputation: 31
I have four 3d matrices: sliced_qbot.Rdata
, sliced_q2m.Rdata
, sliced_ubot.Rdata
, and sliced_vbot.Rdata [256,128,360]
. The first two matrices have a mix of reals and NA
's and the last two have all reals. However, when I try to obtain summary statistics for the two NA
containing matrices using:
summary(sliced_q2m.Rdata)
summary(sliced_qbot.Rdata)
It returns min=0 q1=0 med=0 mean=0 q3=0 max=0, NA's =7212960
for both
Whereas summary(sliced_ubot.Rdata)
and summary(sliced_vbot.Rdata)
do not have any NA values and return and actual summary. I'm not sure why summary isn't working for the two matrices with NA values, but it works for the two without NA values.
Upvotes: 1
Views: 264
Reputation: 31
DOH! Okay so I just had to increase the number of digits displayed. Most of my data points are really small numbers, so I should have realized I would need more digit spaces.
> options(digits=20)
> summary(sliced_q2m)
returns an actual summary
Min.1st Qu. Median Mean 2.6467755999999998e-06 5.5907318890000002e-04 3.2247315394000001e-03 4.8551256022999999e-03 3rd Qu. Max. NA's 6.6539720865000001e-03 2.3001585155700000e-02 7212960
Thanks for the help though!
Upvotes: 2
Reputation: 160437
I suggest this is due to display rounding.
set.seed(42)
rndm <- rexp(10000, 1e8)
summary(rndm)
# Min. 1st Qu. Median Mean 3rd Qu. Max.
# 1.950e-12 2.876e-09 6.887e-09 1.007e-08 1.413e-08 1.058e-07
summary(matrix(rndm, ncol = 2))
# V1 V2
# Min. :1.950e-12 Min. :2.720e-12
# 1st Qu.:2.946e-09 1st Qu.:2.811e-09
# Median :6.967e-09 Median :6.823e-09
# Mean :1.023e-08 Mean :9.896e-09
# 3rd Qu.:1.417e-08 3rd Qu.:1.408e-08
# Max. :8.462e-08 Max. :1.058e-07
Inject a single NA
to trigger a slightly different logic for display:
summary(matrix(c(NA, rndm[-1]), ncol = 2))
# V1 V2
# Min. :0e+00 Min. :2.720e-12
# 1st Qu.:0e+00 1st Qu.:2.811e-09
# Median :0e+00 Median :6.823e-09
# Mean :0e+00 Mean :9.896e-09
# 3rd Qu.:0e+00 3rd Qu.:1.408e-08
# Max. :1e-07 Max. :1.058e-07
# NA's :1
You can dive in a little to look at the first column with:
summary(matrix(c(NA, rndm[-1]), ncol = 2)[,1])
# Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
# 0e+00 0e+00 0e+00 0e+00 0e+00 1e-07 1
which still looks all zeroes until
str(summary(matrix(c(NA, rndm[-1]), ncol = 2)[,1]))
# Classes 'summaryDefault', 'table' Named num [1:7] 1.95e-12 2.95e-09 6.97e-09 1.02e-08 1.42e-08 ...
# ..- attr(*, "names")= chr [1:7] "Min." "1st Qu." "Median" "Mean" ...
which shows that the actual statistics are just very small numbers and rounded for display purposes.
You can also confirm this is a display-rounding issue with this:
options(digits=15)
summary(matrix(c(NA, rndm[-1]), ncol = 2))
# V1 V2
# Min. :1.9490000e-12 Min. :2.71670054640e-12
# 1st Qu.:2.9464250e-09 1st Qu.:2.81112083154e-09
# Median :6.9705950e-09 Median :6.82337492704e-09
# Mean :1.0235797e-08 Mean :9.89606947511e-09
# 3rd Qu.:1.4169548e-08 3rd Qu.:1.40828140108e-08
# Max. :8.4623358e-08 Max. :1.05845029551e-07
# NA's :1
Upvotes: 0