Lesson - 2A2

The "as" function helps when needing to translate between different classes and utilizing as will ensure the values represented are displayed properly "as" - See below for more explanation by means of examples:

x <- 0:6

as.character(x)
"0" "1" "2" "3" "4" "5" "6"

One command which can be useful when dealing with a potentially unknown object type you can use the function class() -

class(x)
"integer"

as.numeric(x)
0 1 2 3 4 5 6

as.logical(x)
FALSE TRUE TRUE TRUE TRUE TRUE TRUE

as.complex(x)
0+0i 1+0i 2+0i 3+0i 4+0i 5+0i 6+0i

Comments