What is as.double() Function in R

The as.double() function in R converts an integer to a double class.

Syntax

as.double(x, …)

Parameters

  1. x: It is an object to be coerced or tested.
  2. : further arguments passed to or from other methods.

Example

x <- 1:5
y <- as.double(x)

y
typeof(y)

Output

[1] 1 2 3 4 5
[1] "double"

You can see that we converted a numeric class to a double class using the as.double() function.

is.double() function in R

To check if a data object has a double class in R, you can use the is.double() function. It returns TRUE if the value has class double and FALSE otherwise.

x <- 1:5
y <- as.double(x)

is.double(y)

Output

[1] TRUE

The as.double() function converts a numeric class to double, and that’s why it returns TRUE.

That’s it.

Leave a Comment