R – Type of Vector
To programmatically get type of a vector in R, call typeof() function and pass the vector to it as argument.
In this tutorial, we will learn how to find the type of a given vector using typeof() function, with examples.
The syntax to use typeof() function to get the data type of vector
The function returns a character string representing the type of the given vector.
In the following program, we create a vector of type integer, and find the type using typeof() function.
x <- c(1L, 2L, 4L, 8L) print(typeof(x))
Now, let us create a vector with logical values, and find this vector’s type using typeof().
x <- c(TRUE, TRUE, FALSE) print(typeof(x))
In this R Tutorial, we learned how to find the type of a given vector, using typeof() function, with the help of examples.