Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
r
communitycreator

What is the class() function in R?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The class() function in R is used to return the values of the class attribute of an R object.

Syntax

Following is the syntax for the method:

class(x)

Parameters

The class() function takes the parameter value:

  • x: This represents the R object whose class attribute is to be determined.

Return value

The class() function returns the class attribute of an R object.

Example

Let’s look at the code below:

# creating R objects
mydate <- 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() function 
class(mydate)
class(myfunction)
class(myname)
class(mydf)
Implementing the class() function

Explanation

In the code above:

  • Lines 2 to 5: We create different R objects.
  • Lines 9 to 12: We obtain the class attributes of the R objects we created using the class() function.

RELATED TAGS

function
r
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring