The class()
function in R is used to return the values of the class attribute of an R object.
Following is the syntax for the method:
class(x)
The class()
function takes the parameter value:
x
: This represents the R object whose class attribute is to be determined.The class()
function returns the class attribute of an R object.
Let’s look at the code below:
# creating R objectsmydate <- as.Date('2015-03-12')myfunction <- function(x) { x*x}myname <- "Theo"mydf <- data.frame(c1=1:2, c2=letters[1:2])# getting their class attributes using the class() functionclass(mydate)class(myfunction)class(myname)class(mydf)
In the code above:
class()
function.