What is the is.numeric() function in R?
Overview
In R, the is.numeric() function returns a logical value, TRUE or FALSE, indicating if the argument passed to it has a base type of the class double or integer and the values are regarded as numeric.
Syntax
is.numeric(x)
Syntax for the is.numeric() function
Parameters
This function takes a single parameter value, x, which represents an R object to be tested.
Return value
This function returns TRUE if the argument is numeric and FALSE otherwise.
Example
# implementing the is.numeric() functionis.numeric(20)is.numeric("twenty")is.numeric(4.5)
Explanation
Line 2: We use the
is.numeric()function on an argument,20, to check if it is a numeric value or not. It returnstrue.Line 3: We use the
is.nuemric()function on an argument,"twenty", to check if it is a numeric value or not. It returnsfalse.Line 4: We use the
is.numeric()function on an argument,4.5, to check if it is a numeric value or not. It returnstrue.