Open katiehouse3 opened 6 years ago
Not sure if this makes a difference or not, but NaN is different than NA in R world.
https://www.r-bloggers.com/difference-between-na-and-nan-in-r/
This is an issue for me as well. Here is another example, note how calculating the median directly using na.rm=TRUE
returns a number:
> tmp_forecast$median(na.rm=TRUE)$mat
1 2 3 4 5
Saxony 0.01040127 0.04171795 0.01208403 -0.002226797 0.017309182
Saxony-Anhalt 0.03188128 0.02682220 0.02218045 0.023772320 0.017003589
Schleswig-Holstein -0.01680898 -0.01078023 -0.01137909 NA -0.006069802
6
Saxony 0.04642985
Saxony-Anhalt 0.01604485
Schleswig-Holstein 0.03033324
> apply(tmp_forecast$data$arr, FUN=function(x) median(x), MARGIN =c(1,2))
1 2 3 4 5
Saxony 0.01040127 0.04171795 0.01208403 -0.002226797 0.017309182
Saxony-Anhalt 0.03188128 0.02682220 0.02218045 0.023772320 0.017003589
Schleswig-Holstein -0.01680898 -0.01078023 -0.01137909 NA -0.006069802
6
Saxony 0.04642985
Saxony-Anhalt 0.01604485
Schleswig-Holstein 0.03033324
> apply(tmp_forecast$data$arr, FUN=function(x) median(x, na.rm=TRUE), MARGIN =c(1,2))
1 2 3 4 5
Saxony 0.01040127 0.04171795 0.01208403 -0.002226797 0.017309182
Saxony-Anhalt 0.03188128 0.02682220 0.02218045 0.023772320 0.017003589
Schleswig-Holstein -0.01680898 -0.01078023 -0.01137909 0.094572982 -0.006069802
6
Saxony 0.04642985
Saxony-Anhalt 0.01604485
Schleswig-Holstein 0.03033324
If there is an NA value in the simulated incidence matrix, then the
$mean(na.rm=TRUE)
and$median(na.rm=TRUE)
are still outputting NA values.Example