R Double Vectors
R Double Vector is an atomic vector whose type is “double”. A double vector can have numbers of type double or special values like NA, NaN, Inf or -Inf.
In this tutorial, we will learn how to create a double vector in R, with examples.
Allowed Values in Double Vector
The following are the list of values allowed in a double vector.
- Numbers
- NA (Missing Value)
- NaN (Not a Number)
- Inf (Positive Infinity)
- -Inf (Negative Infinity)
Create a Double Vector using c()
To create a double vector, we can use c() function. A number by default is considered double in R.
In the following example, we create a double vector with length 5. We print the type of vector, and the vector contents.
example.R
x <- c(2, 3, 5, 7, 11)
print(typeof(x))
print(x)
Output
[1] "double"
[1] 2 3 5 7 11
A double vector can contain NA
, NaN, Inf and -Inf.
In the following program, we create a double vector with some of the values as NA, NaN, -Inf and Inf.
example.R
x <- c(2, NA, NaN, -Inf, Inf)
print(typeof(x))
print(x)
Output
[1] "double"
[1] 2 NA NaN -Inf Inf
Conclusion
In this R Tutorial, we learned what double vectors are, different values allowed in a double vector, and how to create a double vector, with the help of examples.