Functions to check and change the type of variables
is.X() and as.X() functions
In R there are is.X() and as.X() functions. What’s the difference?
The is.X() functions are logical operations. They will check if a variable is a certain type or not. For instance, is.numeric() will check if the value of a variable is a number and is.matrix() will check if a variable is a matrix. These functions will return TRUE or FALSE. I don’t use these functions often. If I want to know what type a variable is, I use class().
The as.X() functions convert a variable to a different data type. For instance, as.matrix will convert a data frame to a matrix and is.vector() will convert a factor into a vector. I do use these as.X() functions regularly because some functions will only work on a specific data type…
Quizzes