This document provides an overview of the R programming language. It discusses R's history, introduction, basics, data types, operators, control statements, functions, plotting features, comparisons to other languages like Python and Java, advantages like being open source and supporting data analysis and statistics, and disadvantages such as a complicated language. The document serves as an introduction to R programming.
Water Industry Process Automation & Control Monthly - April 2024
R programming Language
1. By – Sarthak Bhargava |
17100BTCSE01269
Topic : R - Programming
Shri Vaishnav Vidyapeeth
Vishwavidyalaya
2. TABLE OF CONTENTS
• History
• Introduction
• R Basics
• Download and Install R
• GUI /IDE
• Datatypes and Operators
• Conditional Statements and Loops
• Functions
• Plotting
• Features
• Comparison with other programming languages
• Merits / Advantages
• Demerits / Disadvantages
• Conclusion
3. History
R is an implementation of the S programming
language combined with lexical scoping semantics, inspired
by Scheme. S was created by John Chambers in 1976, while
at Bell Labs. There are some important differences, but much
of the code written for S runs unaltered.
R was created by Ross Ihaka and Robert Gentleman at
the University of Auckland, New Zealand, and is currently
developed by the R Development Core Team (of which
Chambers is a member). R is named partly after the first names
of the first two R authors and partly as a play on the name of S.
The project was conceived in 1992, with an initial version
released in 1995 and a stable beta version (v1.0) on 29th
February, 2000.
4. Introduction
R is a programming language and software environment for statistical
computing and graphics. The R language is widely used among statisticians
and data miners for developing statistical software and dataanalysis.
It compiles and runs on a wide variety of UNIX platforms, Windows and Mac
OS. R can be downloaded and installed from CRAN website , CRAN stands
for Comprehensive R Archive Network.
5. R Basics
Download and Install R –
1. Download R from (direct download link) –
https://cran.r-project.org/bin/windows/base/R-3.6.3-win.exe
2. Run exe file
-> Select language
-> Select Location
-> Select Component
-> Select startup option
-> After installation click Finish
GUI / IDE
There are many GUI to use R language such as R studio, pycharm etc.
For this ppt, I am going to use pycharm, To use R programming in pycharm Download and install R
plugin and create R project.
( Images at Next Side)
7. Datatypes in R and Operators
R supports various basic Datatype such as Integer,Complex, Boolean, Character etc. and R also support some
objects called R-Object which are –
1. Vectors -Vector is a sequence of data elements of the same basic type.
2. Lists – List is GenericVector.
3. Matrices – It is a collection of data elements arranged in a two-dimensional rectangular layout
4. Arrays – Arrays are the R data objects which can store data in more than two dimensions.
5. Factors – Factors are the data objects which are used to categorize the data and store it as levels.They
can store both strings and integers.
6. Data Frames - A data frame is a table or a
two-dimensional array-like structure in
which each column contains values of
one variable and each row contains one
set of values from each column.
R supports all operator (like other
Programming languages) and have some
more like “<-” which is also assignment
operator
8. Conditional Statements / Control Statements
–
1. If – An if statement consists of a Boolean
expression followed by one or more statements.
2. if…..else – An if statement can be followed by an
optional else statement, which executes when the
Boolean expression is false.
3. switch – A switch statement allows a variable to be
tested for equality against a list of values.
Loops –
1. repeat - Executes a sequence of statements
multiple times and abbreviates the code that
manages the loop variable.
2. while - Repeats a statement or group of
statements while a given condition is true. It tests
the condition before executing the loop body.
3. for - Like a while statement, except that it tests the
condition at the end of the loop body.
Control Statements and loops
Control statements with output
for loop with output
while loop with outputrepeat loop with output
9. Functions
An R function is created by using the keyword function. The basic syntax of an R function definition is as follows −
function_name <- function(arg_1,arg_2 , …..){
Function_body
return_value
}
The different parts of a function are −
1. Function Name − This is the actual name of the function. It is stored in R environment as an object with this name.
2. Arguments − An argument is a placeholder. When a function is invoked, you pass a value to the argument.
Arguments are optional; that is, a function may contain no arguments. Also arguments can have default values.
3. Function Body − The function body contains a collection of statements that defines what the function does.
4. Return Value − The return value of a function is the last expression in the function body to be evaluated.
Some of R built-in functions are –
1. c() – This is a generic function which combines its arguments.
2. seq() – Create Sequence of Number
3. mean() – Give mean of argument
4. sum() – Give Sum of arguments
5. plot() – Plot graph of argument
11. As stated earlier, R is a programming language and software environment for
statistical analysis, graphics representation and reporting. The following are the
important features of R −
• R is a well-developed, simple and effective programming language which includes conditionals,
loops, user defined recursive functions and input and output facilities.
• R has an effective data handling and storage facility,
• R provides a suite of operators for calculations on arrays, lists, vectors and matrices.
• R provides a large, coherent and integrated collection of tools for data analysis.
• R provides graphical facilities for data analysis and display either directly at the computer or printing
at the papers.
Features of R
12. Comparison with other languages
R Python Java
First appeared in 1993 First appeared in 1991 First appeared in 1995
It has more functions and
packages.
It has less functions and
packages.
It has large number of inbuilt
functions and packages.
It is an interpreter base
language
It is an interpreter base
language.
It is interpreter and compiled
based language.
It is statistical design and
graphics Programming
language.
It is general purpose language
It is general purpose
Programming language
designed for web applications
It is difficult to learn and
understand.
It is easy to understand..
It is easy to learn and
understand.
R is mostly use for data
analysis.
Generic programming, tasks such
as design of softwares.
Java is mostly used in design
of windows applications and
web
13. Merits / Advantages
1. Open Source
2. Exemplary Support for Data Wrangling
3. The Array of Packages
4. Quality Plotting and Graphing
5. Highly Compatible
6. Platform Independent
7. Eye-Catching Reports
8. Machine Learning Operations
9. Statistics
10. Continuously Growing
14. Demerits / Disadvantages
1. Weak Origin
2. Data Handling
3. Basic Security
4. Complicated Language
5. Lesser Speed
6. Spread Across various Packages
15. Conclusion
• R is a OOPs Programming language which is mostly used by data
analytics and data scientists.
• R is Interpreted language having some syntax of java as well as
Python.
• R supports all datatype and supports different data-structures called
R-objects
• R is mostly used for Plotting Purposes.
• R mostly use Functions and packages.
At last R provides us an Eye-Catching Reports and can easily plot graph
of given data which is easy to read and understand, this is also a reason
why it is soo popular,