I'm new to R and I'm wondering if someone can explain the difference between is.vector()
and is.numeric()
.
-
1`v1 <- letters[1:3]` returns TRUE with `is.vector(v1)` and FALSE for `is.numeric(v1)` – akrun Jan 25 '20 at 20:22
-
3The first tests if an R object is a vector, while the second one tests in an R object is a numeric vector (i.e., the class of that vector)... – David Arenburg Jan 25 '20 at 20:23
-
Does this answer your question? [A comprehensive survey of the types of things in R; 'mode' and 'class' and 'typeof' are insufficient](https://stackoverflow.com/questions/8855589/a-comprehensive-survey-of-the-types-of-things-in-r-mode-and-class-and-type) – NelsonGon Jan 26 '20 at 06:03
2 Answers
is.numeric
is a general test to check whether a vector is numeric or not. It will return TRUE
only if the object passed to it is a vector and consists of only numeric data.
Whereas, is.vector
tests whether the object is a vector or not. It will return TRUE
if the object passed is a vector.

- 1,346
- 3
- 17
is.numeric
returns true if the base type of the class is double
or integer
and when values can reasonably be regarded as numeric. (they should be eligible for arithmetic operations and comparable by their base class)
For any values enclosed in a vector being numeric, (integer and floating-point/decimal values) is.numeric
triggers as TRUE
.
Whereas is.vector
checks the class of your object, whether it falls under the conditions of being a vector. Vectors include different variants pertaining to the type of its contents, which can be numeric
(strictly numbers inclusive of decimal values) or character
or logical (having boolean values TRUE
or FALSE
) or the vector can be raw or complex as well. (You can check the type of vector using typeof()
function)
The distinction is clear as for character values or boolean values in your vector, is.numeric
would return FALSE
as opposed to a TRUE
for is.vector
.
If you were to test the same for data frames instead of vectors, the question would arise between isNumeric
and is.data.frame
.