R Programming

Data Types in R

Most languages support data types such as boolean, integer, float, double, character, string to store various types of information. Based on the type of data opted to store a particular piece of information the programming language along with the underlying OS reserves some memory space. This memory space is referenced by a named identifier called variables. In R, the variables are not declared as data types but R Objects are created and assigned to variables. For example, in most languages like C, Java, C# variables are declared and then values of that type are assigned like

int x = 25;

double rateOfInterest = 8.4;

But in R, simple and complex data structures are created and assigned to a variable and there is no need to declare the type of variable. The basic data types supported by R are as follows:

  1. Logical
  2. Numeric
  3. Integer
  4. Complex
  5. Character
  6. Raw

These data classes are used to build the various data structures / R data objects. The most commonly used data objects in R are

  1. Vectors
  2. Lists
  3. Matrices
  4. Arrays
  5. Factors
  6. Data Frames

Lets first understand the data classes and the information we can store in them and proceed to understand the data structures mostly used in R.

Logical

Logical data types are defined using TRUE or FALSE keywords. Please note these are always in upper case and all other cases such as true, false, True, False can be used for variable names. For example