Tutorial lessons
R (programming language)
Learn R programming with free step-by-step tutorials on vectors, matrices, data frames, OOP, data analysis, ggplot2, visualization, and R packages.
Lessons
Tutorial lessons
R – Lang Roadmap
Introduction to R Fundamentals of R Variables Input and Output Data Structures Vector Matrices Cloud Networking and Scalability Cloud Infrastructure and Architecture Control Flow Control Flow Object O
Introduction of R
Introduction The R Language stands out as a powerful tool in the modern era of statistical computing and data analysis. Widely embraced by statisticians, data scientists, and researchers, the R Langua
Fundamentals of R
Basic Syntax R is a leading language for statistical computing and data analysis, supported by over 10,000 free packages in the CRAN repository. Like other programming languages, R has a specific synt
Variables
R Variables – Creating, Naming and Using Variables in R A variable is a memory space allocated to store specific data. The name associated with the variable is used to interact with this reserved memo
Input and Output
Taking Input from User in R Programming Developers often need to interact with users to gather data or provide results. Most modern programs use dialog boxes or console input for this purpose. In R, i
Data Structures
A data structure is a specific way of organizing and storing data in a computer so that it can be used efficiently. The goal is to optimize time and space complexity for various tasks. In R
Introduction to Vectors in R
Vectors are the most fundamental data structure in R. Almost everything in R—numbers, characters, logical values, and even matrices—is built on top of vectors. Understanding vectors deeply is essentia
Operations on Vectors in R
Operations in detail Vectors are the fundamental data types in R. Any object created is stored as a vector by default. A vector is essentially a sequence of homogeneous data elements, similar to array
Append Operation on Vectors in R Programming
Append Operation on Vectors in detail Vectors are the fundamental data types in R. Any object created is stored as a vector by default. A vector is essentially a sequence of homogeneous data elements,
Dot Product of Vectors in R Programming
Dot Product of Vectors in detail Vectors are the fundamental data types in R. Any object created is stored as a vector by default. A vector is essentially a sequence of homogeneous data elements, simi
Types of Vectors in R Programming
Types of Vectors in detail Vectors in R programming are similar to arrays in C language and are used to hold multiple data values of the same type. One key difference is that in R, the indexing of vec
Assigning Vectors in R Programming
Assigning Vectors in detail Vectors are one of the fundamental data structures in R. They store data of the same type and are equivalent to arrays in many other programming languages. In R, an array i
Length of Vectors – length() Function
The length() function in R is a versatile tool used to determine or set the number of elements in a vector, list, or other objects. Vectors can be of various types such as numeric, character
Creating a Vector of sequenced elements in R Programming – seq() Function
Creating a Vector of sequenced elements in detail Sequenced elements refer to items arranged in a specific order, one after the other. This concept is commonly applied in various fields to organize da
Get the Minimum and Maximum element of a Vector in R Programming – range() Function
Get the Minimum and Maximum element of a Vector in R Programming in detail The range() function in R is used to determine the smallest (minimum) and largest (maximum) values in a given vecto
Formatting Numbers and Strings in R Programming – format() Function
Formatting Numbers and Strings in detail The format() function in R is a versatile tool that allows us to convert various objects, such as character strings, date/time data, and numeric valu
Replace the Elements of a Vector in R Programming – replace() Function
replace() Function in detail The replace() function in R is used to replace specific values in a given vector at specified indices with new values. Syntax: Parameters: Example 1: Output: Exa
Sorting of a Vector in R Programming – sort() Function
sort() Function in detail In R, the sort() function is used to arrange the elements of a vector in either ascending or descending order. It returns a sorted version of the input vector and c
Convert elements of a Vector to Strings in R Language – toString() Function
toString() Function in detail The toString() function in R is used to generate a single character string that describes an R object. Syntax: Parameters: toString() Function in R Language Exa
Extracting Substrings from a Character Vector in R Programming – substring() Function
substring() Function in detail The substring() function in R programming is used to extract substrings from a character vector. It allows you to extract specific substrings or character
R – Matrices
R – Matrices in detail A matrix is a two-dimensional structure in R that organizes data into rows and columns. Rows extend horizontally, while columns extend vertically. In R, matrices are homogeneous
Create Matrix from Vectors
Matrix from Vectors in detail In R, a vector is a basic data structure consisting of homogeneous elements. These elements can have various data types, such as integer, double, character, logical, comp
Operations on Matrices in R
Operations on Matrices in detail Matrices in R consist of values, either real or complex numbers, arranged in a structured format with a fixed number of rows and columns. They are essential for repres
Algebraic Operations on a Matrix in R
Algebraic Operations on a Matrix in detail In this article, we will explore how to perform algebraic operations on matrices using the R programming language. Let’s begin by understanding what a matrix
Combining Matrices in R
Combining Matrices in detail Combining matrices involves merging two or more smaller matrices, either by rows or columns, to create a larger matrix. This operation is a fundamental data manipulation t
Matrix Transpose in R
Matrix Transpose in detail The transpose of a matrix is an operation that swaps its rows and columns. This means that the element at position (i,j)(i, j)(i,j) in the original matrix moves to
Inverse of Matrix in R
Operations on Lists in detail The inverse of a matrix plays a crucial role in solving systems of linear equations. It is similar to the reciprocal of a number in regular arithmetic. If a matrix A
Working with Sparse Matrices in R Programming
Working with Sparse Matrices in detail Sparse matrices are data structures optimized for storing matrices with mostly zero elements. Using a dense matrix for such data leads to inefficient memory usag
Check if the Object is a Matrix in R Programming – is.matrix() Function
is.matrix() Function in detail The is.matrix() function in R is used to determine whether a given object is a matrix. It returns TRUE if the object is a matrix and FALSE
Convert an Object into a Matrix in R Programming – as.matrix() Function
as.matrix() Function in detail The as.matrix() function in R is used to transform different types of objects into matrices. This is useful when working with structured data that needs to be
Get or Set Dimensions of a Matrix in R Programming – dim() Function
dim() Function in detail The dim() function in R is used to obtain or modify the dimensions of an object. This function is particularly helpful when working with matrices, arrays, and data f
Calculate Cumulative Sum of a Numeric Object – cumsum() Function
cumsum() Functionin detail The cumulative sum is the running total of a sequence of numbers, where each value in the output is the sum of all previous values including the current one. cumsum() F
Compute the Sum of Rows of a Matrix or Array – rowSums Function
rowSums Function in detail The rowSums() function in R is used to compute the sum of rows in a matrix, array, or data frame. It is particularly useful when dealing with large datasets where
Two Dimensional List in R Programming
Reading Tabular Data in detail A list in R is a data structure that can store elements of different types, including numbers, strings, vectors, and even other lists. This makes lists flexible and usef
Cloud Infrastructure and Architecture
Introduction Cloud Infrastructure and Architecture define how computing resources are designed, organized, delivered, and scaled over the internet. Instead of owning physical servers and data centers,
Introduction to Factors in R
Introduction Factors are a special type of data structure in R used to represent categorical data. Categorical data consists of values that belong to a finite set of categories, such as gender, educat
Level Ordering of Factors in R Programming
Level Ordering of Factors in detail Factors are data objects used to categorize data and store it as levels. They can store both strings and integers. Factors represent columns with a limited number o
Convert Factor to Numeric and Numeric to Factor in R Programming
Convert Factor to Numeric and Numeric to Factor in detail Factors are data objects used to categorize data and store it as levels. They can store both strings and integers. Factors represent columns w
Check if a Factor is an Ordered Factor in R Programming – is.ordered() Function
is.ordered() Function in detail The is.ordered() function in R is used to determine whether a given factor is an ordered factor. Syntax: Parameters: Example 1: Checking an Unordered Fac
Checking if the Object is a Factor in R Programming – is.factor() Function
is.factor() Function in detail The is.factor() function in R is used to determine whether a given object is a factor. It returns TRUE if the object is a factor and FALSE
Convert a Vector into Factor in R Programming – as.factor() Function
as.factor() Function in detail The as.factor() function in R is used to transform a given object, typically a vector, into a factor. Syntax: Parameters: Example 1: Converting a Character Vec
Control Flow in R Programming
Control Statements Control statements are constructs used to manage the flow and execution of a program based on specified conditions. These structures enable decision-making after evaluating variable
Strings in R Programming
Introduction to Strings in R Programming In R, strings are sequences of characters used to store and manipulate textual data. Strings are essential in data analysis because real-world data often inclu
Working with Text in R
Text in detail R is widely used for statistical computing and data analysis, making it a preferred choice for statisticians and data miners. It includes support for machine learning algorithms, regres
String Matching in R Programming
String Matching in detail String matching is a fundamental operation in any programming language. It is useful for locating, modifying, and removing specific substrings within a larger text. In R, str
Concatenate Two Strings in R Programming
Introduction String concatenation means joining two or more strings together to form a single string. In R, string concatenation is a very common operation used in: R provides multiple built-in functi
How to find SubString in R programming?
String Manipulation in detail In this article, we will explore different ways to find substrings in the R programming language. R provides multiple methods for substring operations, including: Method
Finding the length of string in R programming – nchar() method
nchar() method in detail The nchar() function in R is used to determine the number of characters in a string object. Syntax: Return Value: The function returns the length (number of characte
Adding elements in a vector in R programming – append() method
append() method in detail The append() function in R is used to insert values into a vector at a specified position. If no position is mentioned, the values are added at the end of the vecto
Convert string from lowercase to uppercase in R programming – toupper() function
toupper() function in detail The toupper() function in R is used to convert a lowercase string to an uppercase string. Syntax: Return: Returns the uppercase version of the given string.
Convert String from Uppercase to Lowercase in R programming – tolower() method
tolower() Method in detail The tolower() function in R is used to convert uppercase letters in a string to lowercase. Syntax: Return: Returns the string in lowercase. Example 1: Output:
Splitting Strings in R programming – strsplit() method
strsplit() method in detail The strsplit() function in R is used to divide a string into smaller parts based on a specified delimiter. Syntax of strsplit() Parameters: Return Value: It
Print a Formatted string in R Programming – sprintf() Function
sprintf() Function in detail The sprintf() function in R uses a format specified by the user to return the formatted string, inserting the values provided. Syntax: Parameters: Example 1: For
Object Oriented Programming
max() function in detail max() Function in R LanguageThe max() function in R is used to identify the largest element in a given object. This object can be a vector, list, matrix, data f
Introduction to Object-Oriented Programming in R Language
Introduction Object-Oriented Programming (OOP) is a programming paradigm that organizes software design around objects, rather than functions and logic alone. Objects represent real-world entities and
Classes in R Programming
Classes in detail Classes and Objects form the foundation of Object-Oriented Programming (OOP). They revolve around real-world entities. In R, everything is treated as an object. An object is essentia
Objects in R Programming
Introduction to Objects in R In R, everything is an object. This is one of the most important concepts to understand when learning R programming. Variables, data structures, functions, models, and eve
Encapsulation in R Programming
Encapsulation While working with classes and dealing with sensitive data, implementing global access to all the variables used within the program code is not a good choice because then the chances of
Polymorphism in R Programming
Polymorphism R supports parametric polymorphism, enabling methods (functions) to operate on a variety of object types. Unlike class-based systems, R’s methods are tied to functions rather than cl
R – Inheritance
Inheritance and Their Types Inheritance is one of the key concepts in object-oriented programming, enabling new classes to be derived from existing or base classes, thereby enhancing code reusability.
Abstraction in R Programming
Abstraction and Their Types People who have been using the R programming language for a while are likely familiar with passing functions as arguments to other functions. However, they are less likely
Looping over Objects in R Programming
Looping over Objects and Their Types The “for” loop, while a fundamental construct in programming, is often criticized for its high memory consumption and slow execution, especially when dealing with
R – Creating, Listing, and Deleting Objects in Memory
Creating, Listing, and Deleting Objects in Memory with Example In R, what is often referred to as an “object” is equivalent to what many other programming languages call a “variable.” Objects and vari
S3 class in R Programming
S3 class and Their Types In R, everything is considered an object. Objects have attributes, and one of the most commonly associated attributes is the class. The class() command is used
Explicit Coercion in R Programming
Explicit Coercion and Their Types Explicit coercion refers to the process of converting an object from one type of class to another using specific functions. These functions are similar to base functi
R6 Classes in R Programming
R6 Classes and Their Types In Object-Oriented Programming (OOP) within the R language, encapsulation refers to bundling data and methods within a class. The R6 package in R provides an encap
Getting attributes of Objects in R Language – attributes() and attr() Function
attributes() Function The attributes() function in R is used to retrieve all the attributes of an object. Additionally, it can be used to set or modify attributes for an object. Syntax: Para
Get or Set names of Elements of an Object in R Programming – names() Function
names() The names() function in R is used to either retrieve or set the names of elements in an object. The function can be applied to vectors, matrices, or data frames. When assigning names
Get the Minimum element of an Object in R Programming – min() Function
min() function min() Function in R Language The min() function in R is used to determine the smallest value within an object. This object can be a vector, list, matrix, data frame, or o
Get the Maximum element of an Object in R Programming – max() Function
Object Oriented Programming R programming integrates object-oriented programming concepts, providing classes and objects as fundamental tools to simplify and manage program complexity. R, though prima
Error Handling in R Programming
Handling Errors Error handling is the process of dealing with unexpected or anomalous errors that could cause a program to terminate abnormally during execution. In R, error handling can be implemente
File Handling
In R Programming, handling of files such as reading and writing files can be done by using in-built functions present in R base package. In this article, let us discuss reading and writing of CSV file
Packages in R Programming
Packages in detail Packages in the R programming language are collections of R functions, compiled code, and sample data stored under a directory called “library” within the R environment. By default,
Introduction to Packages
Introduction In R, packages are collections of functions, datasets, documentation, and compiled code that extend the base functionality of R. Packages allow users to perform complex tasks easily witho
dplyr Package in R Programming
dplyr Package in detail The dplyr package in the R programming language is a powerful tool for data manipulation. It provides a streamlined set of functions (or verbs) to handle common data
Grid and Lattice Packages in R Programming
Grid and Lattice Packages in detail Every programming language offers packages to implement various functions. In R programming, packages bundle related functions to streamline development. To utilize
Shiny Package in R Programming
Shiny Package in detail Packages in the R programming language are a collection of R functions, compiled code, and sample data. They are stored under a directory called “library” in the R environment.
Tidyverse Packages
Tidyverse Packages in detail When working with Data Science in R, the Tidyverse packages are your ultimate toolkit! These packages were designed specifically for Data Science and share a unified desig
Data Munging in R Programming
Data Munging in detail Data Munging refers to the process of transforming raw or erroneous data into a clean and usable format. Without data munging—whether done manually by a user or through an
Data Handling in R Programming
Data Handling in detail The R programming language is extensively used for statistical analysis and data visualization. Handling data involves importing and exporting files, and R simplifies this proc
Importing Data in R Script
Data Handling in detail R offers several functions to import data from various file formats into your working environment. This guide demonstrates how to import data into R using different file format
How To Import Data from a File in R Programming
Import Data from a File in detail Data is a collection of facts and can exist in multiple formats. To analyze data using the R programming language, it first needs to be imported. R allows importing d
Exporting Data from scripts in R Programming
Exporting Data in detail When a program terminates, all data held in the program is lost. To ensure data persistence, we store the fetched information in files. This enables transferring data across s
Working with CSV files in R Programming
Working with CSV files in detail In this article, we will explore how to handle CSV files in the R programming language. Understanding CSV Files in R CSV (Comma-Separated Values) files are plain text
Working with XML Files in R Programming
Working with XML Files in detail XML, short for Extensible Markup Language, is composed of markup tags where each tag represents specific data within an XML file. To manipulate XML files in R, we need
Working with Excel Files in R Programming
Working with Excel Files in detail Excel files commonly have extensions such as .xls, .xlsx, and .csv (comma-separated values). To begin working with Excel files in R, they need to
Working with JSON Files in R Programming
Working with JSON Files in detail JSON (JavaScript Object Notation) is a widely used data format that stores information in a structured and readable manner, using text-based key-value pairs. Just lik
Reading Tabular Data from files in R Programming
Reading Tabular Data in detail In data analysis, it is often necessary to read and process data stored outside the R environment. Importing data into R is a crucial step in such cases. R supports mult
Working with Databases in R Programming
Working with Databases in detail In R, working with datasets is a crucial aspect of statistical analysis and visualization. Instead of manually creating datasets in the console each time, we can retri
Database Connectivity with R Programming
Import Data from a File in detail A database is a structured collection of organized data that allows easy access, storage, and management. It can be handled using a Database Management
Manipulate R Data Frames Using SQL
R Data Frames Using SQL in detail The sqldf package in R enables seamless manipulation of data frames using SQL commands. It provides an efficient way to work with structured data and can be
Data Visualization in R Programming
Introduction to Data Visualization Data Visualization is the process of converting raw data into visual representations such as graphs, charts, and plots so that information can be understood quickly
Data visualization with R and ggplot2
Data visualization with ggplot2 in detail Data visualization with R and ggplot2, also known as the Grammar of Graphics, is a free, open-source, and user-friendly visualization package w
R – Line Graphs
R – Line Graphs in detail A line graph is a chart used to display information in the form of a series of data points. It utilizes points and lines to represent changes over time. Line graphs
Adding Straight Lines to a Plot in R Programming – abline() Function
abline() Function in detail The abline() function in R is used to add one or more straight lines to a graph. It can be used to add vertical, horizontal, or regression lines to a plot. Syntax
Addition of Lines to a Plot in R Programming – lines() Function
lines() Function in detail The lines() function in R is used to add lines of different types, colors, and widths to an existing plot. Syntax: Parameters: Adding Lines to a Plot using li
Histograms in R language
Histograms in detail A histogram is a graphical representation of statistical data that groups data points into specified ranges. The rectangular bars in a histogram represent frequencies, with their
R – Pie Charts
R – Pie Charts in detail A pie chart is a circular statistical graphic divided into slices to illustrate numerical proportions. Each sector (or slice) represents the relative sizes of data. It is also
Scatter plots in R Language
Scatter plots in detail A scatter plot is a set of dotted points representing individual data pieces on the horizontal and vertical axis. In a graph in which the values of two variables are plotted al
Create Dot Charts in R Programming – dotchart () Function
dotchart () Function in detail The dotchart() function in R is used to create a Cleveland dot plot, where individual data points are represented as dots. This type of plot is particularly us
Boxplots in R Language
Boxplots in detail A box graph (or boxplot) is used to display the distribution of data based on a five-number summary: the minimum, first quartile, median, third quartile, and maximum. In R, you can
Stratified Boxplot in R Programming
Stratified Boxplot in detail A boxplot is a graphical summary that represents groups of numerical data using their quartiles. Since boxplots are non-parametric, they display the variation in samples f
Create a Heatmap in R Programming – heatmap() Function
heatmap() Function in detail A boxplot is a graphical summary that represents groups of numerical data using their quartiles. Since boxplots are non-parametric, they display the variation in samples f
R – Pareto Chart
Pareto Chart in detail The Pareto chart combines a bar chart and a line chart: the left vertical axis shows the frequency of occurrences for different categories (sorted in descending order), and the
R – Waffle Chart
Waffle Chart in detail A waffle chart provides a clear visual representation of how individual components contribute to a whole. It’s particularly useful for tracking progress toward a goal or for sho
Draw a Quantile-Quantile Plot in R Programming
Draw a Quantile-Quantile Plot in detail A Quantile-Quantile (Q-Q) plot is a graphical tool used to compare two probability distributions by plotting their quantiles against each other. Often, it is em
Describe Parts of a Chart in Graphical Form in R Programming – legend() Function
legend() Function in detail The legend() function in R is used to add legends to an existing plot. A legend is an area within the graph plot that describes the elements of the plot. The lege
Principal Component Analysis with R Programming
Principal Component Analysis in detail Principal Component Analysis (PCA) is a technique used to analyze the linear components of all existing attributes in a dataset. Principal components are linear
Intoduction to Arrays
R – Array Arrays are fundamental data storage structures defined with a specific number of dimensions. They are used to allocate space in contiguous memory locations. In R Programming, one-dimensional
Multidimensional Array in R
Multidimensional Array in detail Arrays in R are data objects that store data in more than two dimensions. For example, if we create an array of dimensions (2, 3, 4), it forms 4 rectangular matri
Array Operations in R Programming
Array Operations in detail Arrays are R data objects that store data in more than two dimensions. Arrays are n-dimensional data structures. For example, if we create an array of dimensions (2, 3, 3),
Sorting of Arrays in R Programming
Sorting of Arrays in details A vector is a one-dimensional array, defined by a single length dimension. A vector can be created using the c() function by passing a list of values. Sorting ca
Convert values of an Object to Logical Vector in R Programming – as.logical() Function
as.logical() Function in details The as.logical() function in R is used to convert an object to a logical vector. Syntax: Parameters: Example 1: Basic Example of as.logical() Funct
Outer() Function in R
Outer() Function in detail A flexible tool for working with matrices and vectors in R is the outer() function. It enables you to create a new matrix or array by applying a function to every possible c
Get Exclusive Elements between Two Objects in R Programming – setdiff() Function
setdiff() Function in detail The setdiff() function in R is used to find elements that are present in the first object but not in the second object. Syntax: Parameters: Example 1: Using