All the decimal values are numerical values in R. That means if you assign any decimal value to that variable in R, it will become numeric. To check whether the argument is numeric or a data.frame with numeric columns in R, use the is.numeric() function.
is.numeric in R
The is.numeric in R is a built-in function used to check if the object passed to it as an argument is of numeric type. For example, the is.numeric() method returns TRUE if its argument is of mode “numeric” (which is either “double” or “integer“).
obj: It is an R Object to test whether it is numeric or not.
In this example, we will check 1, 0, negative, double, positive values, and complex values.
is.numeric(1) is.numeric(0) is.numeric(2.1) is.numeric(-1.9) is.numeric(1 + 6i)
 TRUE  TRUE  TRUE  TRUE  FALSE
If we pass integer(negative or positive) or double values to the is.numeric() method, it returns TRUE, but if we pass the complex or factor value, it returns FALSE.
The double is the name of the type, and a numeric is the name of the mode and the implicit class.
Checking if a matrix is numeric
To create a matrix in R, use the matrix() function. After creating a matrix, pass the matrix to the is.numeric() function.
mat <- matrix(c(1:16), 4, 4) is.numeric(mat)
That’s it for this tutorial.
Krunal Lathiya is an Information Technology Engineer by education and web developer by profession. He has worked with many back-end platforms, including Node.js, PHP, and Python. In addition, Krunal has excellent knowledge of Data Science and Machine Learning, and he is an expert in R Language. Krunal has written many programming blogs, which showcases his vast expertise in this field.