Numbers
Numerical values and vectors of numerical values can be of type double, complex or integer. There is no single
precision data type. The default type is double.
Exponential notation can be used to represent numbers; e.g. x <- 1.0e10;
assigns the value 1.0x1010
to x.
Predefined values
pi ratio of circumference of a circle to its diameter 1i unit imaginary value NA a logical constant indicating a missing value. Inf representation of `infinity'. NaN representation of `Not a Number'.
Complex numbers
The complex component of a complex number can be specifed by Xi, where X is a floating point value.
For example,
sqrt(-1) is represented as
1i
This is the numeric value one followed by the letter i. In order to get the standard mathematical functions to produce complex results, one must specify the argument as a complex quantity. For example, to compute the complex value sqrt(-1) requires
> sqrt(-1.0 + 0i); [1] 0+1i
To change the maximal number of digits that are displayed when numbers are printed use the command
options(digits=XXX);
where XXX
is the number of digits desired.
Use Machine() to display the characteristics of the numbers used to store double, integers etc.
See Also : Displaying/Saving Results
Original Documentation : double, complex,
integer, Inf,
NAN, NA, Machine,
options
Samples
# Printing out 10 digits of the the internal value of pi
options(digits = 10) pi [1] 3.141592654
# Evaluating the sqrt(-1)
sqrt(-1.0 + 0.0i) [1] 0+1i
# Evaluating the complex exponential of i
exp(1i) [1] 0.5403023+0.841471i
# NA's (not assigned's) are the default value when an array is resized and new values are introduced ...
z <- double(); z[3] <- 3.0 z [1] NA NA 3
# Generate Inf and NaN's
1.0/0.0 [1] Inf 0.0/0.0 [1] NaN sqrt(-1.0) [1] NaN Warning message: NaNs produced in: sqrt(-1)
UCLA Mathematics Department | ©2000 |