as.double & is.double Functions in R (2 Examples)
In this article, I’ll explain how to apply the as.double and is.double functions in the R programming language.
The article is structured as follows:
Sound good? Let’s dive right in!
Definitions & Basic R Syntaxes of as.double and is.double Functions
Definitions: You can find the definitions of the as.double and is.double functions below.
- The as.double R function converts an integer to the double class.
- The is.double R function tests whether a data object has the double class.
Basic R Syntaxes: Please find the basic R programming syntaxes of the as.double and is.double functions below.
as.double(values) # Basic R syntax of as.double function is.double(values) # Basic R syntax of is.double function |
as.double(values) # Basic R syntax of as.double function is.double(values) # Basic R syntax of is.double function
I’ll show in the following two examples how to use the as.double and is.double functions in the R programming language.
Creation of Example Data
Consider the following example data:
x <- 1:5 # Example vector x # Print example vector # 1 2 3 4 5 |
x <- 1:5 # Example vector x # Print example vector # 1 2 3 4 5
The previously shown output of the RStudio console shows the structure of our example data: It’s an integer vector ranging from 1 to 5.
Example 1: Convert Numeric/Integer to Class double
In Example 1, I’ll illustrate how to convert an integer to the double class in R using the as.double function.
x_double <- as.double(x) # Apply as.double x_double # Print converted vector # 1 2 3 4 5 |
x_double <- as.double(x) # Apply as.double x_double # Print converted vector # 1 2 3 4 5
The previous output looks exactly the same as the original output. However, the data type was changed to the double class. In the next example I’ll show how to check that…
Example 2: Test whether Data Object has Class double
In this Example, I’ll illustrate how to check if a data object has the data type double. For this task, we can use the is.double function. Let’s first apply the is.double function to our original example vector:
is.double(x) # Apply is.double to integer # FALSE |
is.double(x) # Apply is.double to integer # FALSE
The RStudio console returns FALSE, i.e. the original vector does not have the double mode.
Let’s also apply the is.double function to our converted data:
is.double(x_double) # Apply is.double to converted data # TRUE |
is.double(x_double) # Apply is.double to converted data # TRUE
The RStudio console returns TRUE, indicating that the conversion to the double class worked!
Video & Further Resources
Have a look at the following video of my YouTube channel. In the video, I’m explaining the R codes of this post.
Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.
If you accept this notice, your choice will be saved and the page will refresh.
Furthermore, you may read some of the related tutorials of this website. I have published numerous tutorials already.
- single & as.single Functions in R
- Convert Data Frame Column to Numeric
- Convert Data Frame with Date Column to Time Series Object
- Convert UNIX Timestamp to Date Object
- Convert Character String to Date Object
- Convert Character to Factor
- R Functions List (+ Examples)
- The R Programming Language
Summary: In this R tutorial you learned how to use the as.double and is.double functions. In case you have any further questions, don’t hesitate to let me know in the comments.
Statistics Globe Newsletter