Skip to content

Non-numbers #5

@kwstat

Description

@kwstat

Your article is extremely thorough. You touched on a few of these points below, but maybe there's something interesting here below. This is not really an "issue", more of a comment.

# Things that are not floating point numbers ---

# In theory:
NaN  # Not A (floating point) Number.  IEEE 754 standard.
NA   # Placeholder for an unknown value. Invented by R. Logical.
NULL # Empty object (like an empty set).  Nothing.
Inf  # Infinity
-Inf # Negative infinity

# In practice:
# Any mental model of NA/NaN will fail you. Dante's Inferno.

length(NA)   # 1  Something there, but we don't know what.
length(NaN)  # 1  Something there, but not representable.
length(NULL) # 0  Nothing there.

sqrt(-1)             # NaN. 'i' in mathematics, not defined in floating point.

# NaN is an NA, but NA is not an NaN
is.nan(NA) # FALSE
is.na (NaN) # TRUE

min(c())               # Inf
min(c(NA), na.rm=TRUE) # Inf
min(NaN)               # NaN

max(c())               # -Inf
max(c(NA), na.rm=TRUE) # -Inf
max(NaN)               # NaN

# https://en.wikipedia.org/wiki/Empty_sum
sum(NA)               # NA
sum(NA, na.rm=TRUE)   # 0    # Horrible

mean(NA)              # NA
mean(NA, na.rm=TRUE)  # NaN

var(NA)               # NA
var(NA, na.rm=TRUE)   # NA

# https://en.wikipedia.org/wiki/Empty_product
prod(NA)              # NA
prod(NA, na.rm=TRUE)  # 1    # Horrible

NA | TRUE   # TRUE
NA & FALSE  # FALSE

# https://en.wikipedia.org/wiki/Division_by_zero
0/0   # NaN
1/0   # Inf.  Shouldn't it be NaN?!

Inf >= NA  # NA.  If NA is placeholder, this should be TRUE!

NA * 0      # NA. Because NA could be Inf, and Inf*0 is NaN. Right???
NA ^ 0      # 1
NaN ^ 0     # 1

NA %in% 1:3 # FALSE
match(NA, 1:3) # NA

matrix(nrow=2,ncol=2)  # matrix initializes with NAs
vector(mode="numeric", length=2) # vector initializes with 0s

# NULL can be assigned to an object.
x <- NULL
x
# NULL assigned to list elements removes them.
x <- list(1,"a",TRUE)
x[[1]] <- NULL
x
# NULL assigned to data.frame columns removes them
x <- data.frame(a=1:2, b=3:4)
x
x$a <- NULL
x

# https://blog.revolutionanalytics.com/2016/07/understanding-na-in-r.html
https://stats.stackexchange.com/questions/5686/what-is-the-difference-between-nan-and-na

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions