This is question about R internals. How integer NA values are represented in R? Unlike floating there is no magic bit sequence to represent NaNs.
# Create big array. newer versions of R won't allocate memory to store data
# Instead star/end values are stored internally
a <- 1:1e6 #
# Change some random value. This will cause and array to be allocated
a[123] <- NA
typeof(a)
At this point a is still an array of integers. How a[123] represented internally? Does R use some magic number to indicate that an integer is NA?
My primary interest in internal representation of integers is related to binary read/write (readBin/writeBin). How to handle NA when performing binary I/O with external sources, e.g. via sockets?