Monday, February 24, 2020

R - Programming Objects and Data Structures

As we know that R is an Open Sourced powerful programming language and also known as an Advanced Statistical language which is cross-plateform compatible, so it can be installed on Windows, MAC OSX and Linux and extensively used by Software Programmers, Statisticians, Data Scientists, and Data Miners. 

R language supports object oriented programming or you can also say that everything in R is an object.  An object is nothing and it is a data structure having some attributes and methods which act on its attributes. There are many types of R-objects.

Data Structures
We are very familiar with many language such as C and Java. If you are working within any programming language, then you need to use different variables to store different data. Moreover, variables are reserved in a memory location to store values.  In this case, your program is using some memory area on the computer and you need to define your variable data type where data structures are the only way of arranging data so it can be used efficiently on a computer.
Please keep in mind, R doesn’t have variables declared as some data type and the variables are appointed with R-objects and the knowledge form of the R-object becomes the datatype of the variable. The most popular data structured objects are Vector, Matrix, Array, Lists, Data Frames and Factors.

Vector is the most basic data structure in R programming language. It comes in two parts: Atomic vectors and Lists which comes with three common properties such as:
  1. Type function – what actually it is?
  2. Length function – how many elements does it contain.
  3. Attribute function – extra arbitrary metadata.

Atomic Vectors have four common types such as Numeric Data Type, Integer Data Type, Character Data Type and Logical Data Type

Matrix is a two-dimensional rectangular data set and thus it can be created using vector input to the matrix function. In addition, a matrix is a collection of numbers arranged into a fixed number of rows and columns. There are many applications where we can use them -
  • Matrices are used for carrying out geological surveys. We can represent information in the form of matrices that can be used for plotting graphs, performing statistical operations, etc.
  • To represent the real-world data is like traits of people’s population. They are the best representation method for plotting common survey things.
  • In robotics and automation, matrices are the best elements for the robot movements.
Arrays are multi-dimensional data structures in R programming to stored the data in the form of matrices, row, and as well as in columns where a programmer can use the matrix level, row index, and column index to access the matrix elements.
Please keep in mind, Arrays in R are the data objects which can store data in more than two dimensions.

Lists are the objects which contain elements of different types – like strings, numbers, vectors and another list inside them. A list can also contain a matrix or a function as its elements. In other words, a list is a generic vector containing other objects. A list is created using the list() function.

A Data Frame is an array. Unlike an array, the data we store in the columns of the data frame can be of various types. That is, one column might be a numeric variable, another might be a factor, and a third might be a character variable. All columns have to be of the same length.
Features of a Data Frame: 
  • The column names should be non-empty 
  • The row names should be unique
  • The data stored in a data frame can be of numeric, factor or character type
  • Each column should contain the same number of data items

Factors are special vectors that represent categorical data and can be ordered or unordered. Format for creating an array is:
x <- factor(c("yes", "no", "yes"), levels = c("yes", "no"))

Functions are themselves objects in R which can be stored in the project’s workspace. This provides a simple and convenient way to extend R.  

To Learn more, please visit our YouTube channel at -

To Learn more, please visit our Instagram account at -
To Learn more, please visit our twitter account at -

No comments:

Post a Comment