Data in R can be converted from one class to the other. The functions are prefixed with
Notice the difference between the output of the
Now consider this,
These objects are in numeric class, and converting these to data frame with three variables, would be
Further to matrix class, we have
as.
then followed by the name of the data class that we wish to convert to. Data class in R are the following:- numeric -
as.numeric
; - vector -
as.vector
; - character -
as.character
; - matrix -
as.matrix
; and, - data frame -
as.data.frame
.
Notice the difference between the output of the
data
object and the converted one, data.ch
? The output differs only with this character, "
. This character that encloses every data points suggests that the data is now in character form. And this can be verified using the function class
,
Now consider this,
These objects are in numeric class, and converting these to data frame with three variables, would be
Further to matrix class, we have
Comments
Post a Comment