What is a Class and its Types?

In this lesson, we will learn what Classes and their types are and how to create them in the R language.

Introduction

Functional languages like R make use of the concepts of objects and classes. An object is comprised of a set of variables and functions. A class is a blueprint for an object. It refers to the set of attributes or functions common to all objects of a specific type.

Class Types

R includes 3 class systems, compared to other programming languages that have only one class system.

  • S3 class

  • S4 class

  • Reference class (RC)

Each has unique features and characteristics, so selecting one over the other comes down to personal preference. We provide a concise overview of them below.

S3 Class

The nature of an S3 class is relatively primitive. The object of this class can be generated by simply adding a class attribute to it, and it has no formal definition. Following is an example to make things more clear:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy