What is the significant difference between double-precision data type and numeric data type in R programming?
double is the name of the type. numeric is the name of the mode and also of the implicit class. As an S4 formal class, use "numeric" .
The data types real and double precision are inexact, variable-precision numeric types.
There is a small difference between NUMERIC(p,s) and DECIMAL(p,s) SQL numeric data type. NUMERIC determines the exact precision and scale. DECIMAL specifies only the exact scale; the precision is equal or greater than what is specified by the coder.
Numeric data types are in two categories: exact and approximate. • Exact types include integer and decimal data types. • Approximate types include floating point data types.
From stat.ethz.ch:
It is a historical anomaly that R has two names for its floating-point vectors, double and numeric (and formerly had real). double is the name of the type. numeric is the name of the mode and also of the implicit class. As an S4 formal class, use "numeric". The potential confusion is that R has used mode "numeric" to mean ‘double or integer’
We can think of doubles as belonging to numeric. To see this:
> is.double(1)
[1] TRUE
> is.numeric(1)
[1] TRUE
R normally stores numbers as doubles. Using "numeric()" is the same as "double()." You can also store a number as a single or an integer. Both will be numeric. You may choose to force a number be stored as an integer for performance reasons, but unless you are building a package the trade offs might not be worth your time.
I suggest reading Gillespie's Overview for more info on type and performance.
@tk3: numeric is NOT always identical to double (and real).
> x <- 10
> storage.mode(x)
[1] "double"
> is.numeric(x)
[1] TRUE
> x <- as.integer(x)
> storage.mode(x)
[1] "integer"
> is.numeric(x)
[1] TRUE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With