R – Check if Type of Vector is Double

To check if type of given vector is double in R, call is.double() function and pass the vector as argument to this function. If the given vector is of type double, then is.double() returns TRUE, or else, it returns FALSE.

The syntax to call is.double() to check if type of vector x is double is

is.double(x)

Return Value

The function returns a logical value.

Examples

In the following program, we take a vector in x, and check if this vector is a double vector using is.double() function. We print the value returned by is.double().

example.R

x <- c(2, 4, 6, 8)
result <- is.double(x)
print(result)

Output

[1] TRUE

Now, let us take a vector x of some type other than double, and check the value returned by is.double(x). Since x is not of type double, is.double() must return FALSE.

example.R

x <- c(TRUE, FALSE, FALSE)
result <- is.double(x)
print(result)

Output

[1] FALSE
ADVERTISEMENT

Conclusion

In this R Tutorial, we learned how to check if given vector is of type double, using is.double() function, with the help of examples.