SlideShare a Scribd company logo
1 of 35
Programming Language
History and Introduction
2
 Ris a programminglanguageand free software environmentfor statistical
computing and graphics supported by the R Foundation for Statistical Computing.
 R is widely used by statisticians, data analysts and researchers for developing
statistical software and data analysis.
 It compiles and runs on a wide variety of UNIX platforms, Windows and Mac OS.
 The copyright for the primary source code for R is held by the R Foundation and is
published under the GNU General Public License version 2.0.
History and Introduction
3
 R was created by Ross Ihaka and Robert Gentleman at the University of Auckland, New
Zealand.
 Currently R is developed & maintained by the R DevelopmentCore Team.
 The Applications of R programming language includes :
1.Statical Computing
2.Machine Learning
3.Data Science
 R can be downloaded and installed from CRAN(Comprehensive R Archive Network) website.
 R language is cross platform interoperable and fully portable which means R program that
you write on one platformcan be carried out to other platformand run there.(Platform
independent)
History and Introduction
Top Tier companies using R – companies all over the world use R language for statical analysis.
These are some of top tier companies that uses R.
Company Name Applications
Facebook For behavior analysis related to status updates and profile pictures.
Google For advertising effectiveness and economic forecasting.
Twitter
Microsoft
For data visualization and semantic clustering
Acquired Revolution Rcompany and use it for a variety of
purposes.
Uber For statistical analysis
Airbnb Scale data science. 4
5
Evolution of R
R is a dialect of S language…
 It means that R is an implementation of the S programming language combined
with lexical scoping semantics & inspired by Scheme.
 S language was created by John Chambers in 1976 at Bell Labs.
 A commercial version of S was offered as S-PLUS starting in 1988.
S version1
S version 2
S version 3
S version4
6
Features of R
These are the some of important features of R -
 Ris a simple, effective and well-developed, programming language which
includes conditionals, loops, user defined &recursive functions and input &
output facilities.
 R provides a large, coherent and integrated collection of tools for data
analysis.
 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 graphical facilities for data analysis and display either directly at
the computer or printing at the papers.
7
Features of R
Fast Calculation
Extremely Compatible
Open Source
Cross Platform Support
Wide Packages
Large Standard Library
 Fast Calculation - R can be used to perform complex mathematical
and statistical calculations on data objects of a wide variety.
 Extreme Compatibility - R is an interpreted language which means
that it does not need a compiler to make a program from the code.
 Open Source - R is an open-source software environment. You can
make improvements and add packages for additional functionalities
 Cross Platform Support - R is machine-independent. It supports
the cross-platform operation. Therefore, it can be used on many
different operating systems.
 Wide Packages - CRAN houses more
than 10,000 different packages and extensions that help solve all
sorts of problems in data science.
 Large Standard Library - R can produce static graphics with
production qualityvisualizations and has extendedlibraries
providing interactive graphic capabilities.
8
Syntax of R
Once we have R environment setup, then it’s easy to start our R command prompt by just
typing R in command prompt.
Hello World Program –
>myString <- “Hello world !”
>print(myString)
The [ ] in the output of R can be used
to reference data frame columns
Output :
[1] “Hello World !”
In the Syntax of R we will discuss –
 Data Types
 Variables
 Keywords
 Operators
 Data Structures
Data Types
Logical
9
Integer
Character
Numeric
raw
Complex
DATA
TYPES
In R there are basically 6 data types –
Data Type Examples
Integer 2L,5L,8L
Numeric 6,2,1,9
Logical true,false,0,1
raw Raw Bytes
complex Z=3+7i
Character ‘A’ , ”Aditya” , ”AB12”
Variables
Rules For Naming Variables in R –
1. InR variable name must be a combination of letters, digits, period(.) and
underscores.
2. Itmust start with a letter or period(.) and if it starts with period then it period
should not be followed by number.
3. Reserved words in R cannot be used in variable name.
Valid variables Invalid Variables
 myValue
 .my.value.one
 my_value_one
 Data4
 .1nikku
 TRUE
 vik@sh
 _temp
10
Keywords
11
Reserved Keywords in R – Reserved words are set of words that have special meaning
and cannot be used as names of identifiers.
If Else Repeat While Function
For In Next Break TRUE
FALSE NULL inf NaN -
Reserved Keywords in R
Operators
12
Inany programming language, an operator is a symbol which is used to represent an
action. R has several operators to perform tasks including arithmetic, logical and bitwise
operations.
Operators in R can mainly be classified into the following categories –
1.Arithmetic Operators ={
+, - , *, / , %
%, %/%}
2.Logical Operators={! , & , && , | , | | }
3.Assignment operators={<
-, <
<
- , =, ->, ->>}
4.Relational Operators={<, >, <
=, >
=, !=, =
=
}
Functions
Functions are used to incorporate sets of instructions that you want to use repeatedly. There are two types of functions.
Function
Built In User Defined
13
Built - In
14
Built-in functions are those functions which are provided by R so that we can use directly
within the language and its standard libraries.
In R there are so many built-in functions which make our programming fast and easy.
For Example :
1.The sum(a,b) function will return (a+b)
>print(sum(10,20))
[1] 30
2.The seq(a,b) function is used to get sequence from a to b.
>print(seq(5,15))
[1] 5 6 7 8 9 10 11 12 13 14 15
User Defined
User defined functions are those functions which we define in our code and use them
repeatedly. These functions can be defined with two types.
1.Without Arguments 2.WithArguments
Without Arguments With Arguments
myFunction <- function()
{
#This will be printed on calling this funcition
print(“Without Arguments”)
}
myFunction <- function(a,b)
{
#This function will print sum of passed args
print(a+b)
}
Conditional Statements
16
 Conditional Statements in R programming are used to make decisions based on the conditions.
 Conditional statements execute sequentially when there is no condition around the statements.
In R language we’ll discuss 3 types of Conditional Statements –
1.If - else statements
2. If – else if – else statements
3.Switch statements
If-else
Start
17
Execute
Else block
End
Execute
If Block
Condition
True?
yes no
Syntax –
If(condition) {
expression 1
}
Else {
expression 2
}
Example –
If(a>b) {
print(“a is greater than b”)
}
Else {
print(“ a is less than b”)
}
Switch statement
18
 Inswitch() function we pass two types of arguments one is value and others is list of
items.
 The expression is evaluated based on the value and corresponding item is returned.
 Ifthe value evaluated from the expression matches with more than one item of the
list then switch() function returns the item which was matched first.
Examples:
> switch(2,”Delhi”,”Jaipur”,”Mumbai”)
>[1] “Jaipur”
> a=3
> switch(a,”red”,”blue”,”green”,”yellow”)
> [1] “green”
Loops
Loops
In
R
19
Loops are used When we need to
execute particular code
repeatedly.
3 types
In R Language there are
of Loops –
1.For Loop
2.While Loop
3.Repeat Loop
For Loop
Example to count the number of even numbers in a
vector.
Program -
x <- c(2,5,3,9,8,11,6)
count <- 0
for (i in x) {
if(i %% 2 == 0) {
count=count+1
}
}
print(count)
Output -
[1] 3
No
Last item
Reached??
Body of
For Loop
Yes
For each item
in Sequence
A for loop is used to iterate over a vector in R programming.
Exit Loop
20
21
While Loop
i <- 1
while(i<5) {
print(i)
i=i+1
}
Output –
[1] 1
[1] 2
[1] 3
[1] 4
Yes
No
Condition
True??
Execute code
of while block
InR programming, while loops are used to loop until a specific condition is met.
Program –
Start
Execute code
outside while block
Repeat Loop
 A repeat loop is used to iterate over a block of code multiple number of times.
 There is no condition check in repeat loop to exit the loop.
 We must ourselves put a condition explicitly inside the body of the loop and use the break statement to
exit the loop. Failing to do so will result into an infinite loop.
Example –
x <- 1
repeat {
print(x)
x = x+1
if (x == 4) {
break
}
}
Output –
[1] 1
[1] 2
[1] 3
Body of
Loop
Break
?
Remaining
body of loop Exit
Enter Loop
Yes
No
22
Data Structures
23
DATA
STRUCTURES
Vectors
Factors
Data
Frames
Lists
Matrices
Arrays
A data structure is a particular
organizing data in a computer so
be used effectively. The idea is
way of
that it can
to reduce
the space and time complexities of different
tasks. Data structures in R programming are
tools for holding multiple values.
The most essential data structures used in R include :
 Vectors
 Arrays
 Factors
 Lists
 Matrices
 Data Frames
Vector
24
 Vector is the one of basic data structure of R which supports integer,
double, Character, logical, complex and raw data types.
 The elements in a vector are known as components of a vector.
V ECTOR CREATION
Vector can be created using these two methods :-
1.By Using Colon(:) Operator –
a <- 2:8
print(a) # 2 3 4 5 6 7 8
2.By Using seq() function–
a <- seq(2,10,by=2)
print(a) # 2 4 6 8 10
25
Vector
V ECTOR OPERATIONS
1.CombiningVectors
a <- c(4,3,5)
b <- c(‘x’,’y’,’z’)
c <- c(a,b)
print(c) o/p= 4 3 5 x y z
2.Arithmetic Operations
a <- c(1,2,3)
b <- c(4,5,6)
d <- a+b
print(d) o/p = 5 7 9
3.Numeric Indexing
a <- c(4,3,5)
Print(a[2]) op = 5
4.DuplicateIndexing
a <- c(4,3,5)
print(a[1,2,2,3,3]) o/p=4 3 3 5 5
5.LogicalIndexing
a <- c(4,3,5)
print(a[true,false,true]) o/p = 4 5
6.RangeIndexing
a <- c(1,2,3,4,5,6,7)
print(a[2:6]) o/p = 2 3 4 5 6
26
Array
Arrays allow us to store data in multi - dimensions and use in efficient way.
ARRAY CREATION
Syntax -
Array_Name <- array(data, dim=(row_size,column_size,matrices), dim_names)
ARRAY OPERATIONS
1.Accessing Array Elements –
Accessing array in R is similar to other programming languages like c,c++ and java.
Eg. Print(Arr[2,2])
2.Arithmetic Operations –
Eg. Arr3 <- Arr2 + Arr1
Or
Arr3 = Arr1 – Arr2
Data Frame
27
Data Frame is a table or a two dimensional Array type structure.
Important Considerations
 The Column names should be non-empty.
 The row names should be unique.
 The Data stored in Data Frames can be only Numeric, Factor or Character Type.
 Each column should contain same number of data types.
Data Frame Creation
products <-data.frame(
product_number = seq(1:4)
product_name = c(“Apple”,”Samsung”,”Redmi”,”Oppo”))
print(products)
Product_number Product_name
1 Apple
2 Samsung
3 Redmi
4 Oppo
Lists
28
 List is a data structure which have components of Mixed data types.
 So a vector having elements of different data types is called a list.
 List can be created using list() function.
Eg. –
x <- list( a=“amba”,b=9.23,c=TRUE) #list storing 3 different data types
Accessing List Elements
print(x[‘b’])
print(x[‘a’])
o/p = 9.23
o/p = “amba”
Manipulating List Elements
x[‘a’] <- “nitin”
print([‘a’]) o/p = “nitin”
Matrices
29
 In R two dimensional rectangular data set is known as Matrix.
 A Matrix is created with the help of the input vector to the matrix() function.
 We can Perform addition, subtraction, multiplication and division operations on matrices.
Creating matrix -
Matrix1 <- matrix (2:7,nrow=2,ncol=3)
print(Matrix1)
o/p = 2
3
4 6
5 7
Accessing Elements –
Matrix1[2,3] # 7
Assigning Value –
Matrix1[2,3]=1
Matrices
30
Operations On Matrices
1.Addition :
Matrix3=Matrix1+Matrix2
2.Subtraction :
Matrix3 = Matrix2 – Matrix1
3.Multiply by a Constant :
Ex : 7*Matrix1
4.Identity Matrix :
Ex – diag(5)
5.Transposition
Ex – t(Matrix1)
31
Factors
Factors are data objects which are used to categorise the data and store it as levels.
For example: a data field such as marital status may contain only values from single, married,
separated, divorced, or widowed.
>x
[1] single married married single
Levels : married single
Here, we can see that factor x has four elements and two levels. We can check if a variable is a
factor or not using class() function.
>class(x)
[1] “factor”
>levels(x)
[1] married single
R - Studio
Interacting with R Studio –
 R-Studio is a free and open-source integrated development
environment (IDE) for R, a programming language for statistical
computing and graphics.
 R-Studio was founded by JJ Allaire,creator of the programming
language ColdFusion.
 There are 4 main sections in R-Studio IDE…
1.Code Editor
2.Workspace and History
3.R console
4.Plots and Files
R - Studio
33
 RSTUDIO IS AVAILABLE IN TWO EDITIONS:
1.RSTUDIO DESKTOP, WHERE THE PROGRAM IS RUN
LOCALLY A S A REGULAR DESKTOP APPLICATION.
2.RSTUDIO SERVER, PREPACKAGED DISTRIBUTIONS OF
RSTUDIO DESKTOP ARE AVAILABLE FOR WINDOWS, OS
X, AND LINUX.
 RSTUDIO IS WRITTEN IN THE C+ + PROGRAMMING
LANGUAGE AND USES THE QT FRAMEWORK FOR ITS
gRAPHICAL USER INTERFACE.
Why learn R?
34
R basics for MBA Students[1].pptx

More Related Content

Similar to R basics for MBA Students[1].pptx

STAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdf
STAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdfSTAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdf
STAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdfSOUMIQUE AHAMED
 
R programming Language , Rahul Singh
R programming Language , Rahul SinghR programming Language , Rahul Singh
R programming Language , Rahul SinghRavi Basil
 
Statistical Analysis and Data Analysis using R Programming Language: Efficien...
Statistical Analysis and Data Analysis using R Programming Language: Efficien...Statistical Analysis and Data Analysis using R Programming Language: Efficien...
Statistical Analysis and Data Analysis using R Programming Language: Efficien...BRNSSPublicationHubI
 
Modeling in R Programming Language for Beginers.ppt
Modeling in R Programming Language for Beginers.pptModeling in R Programming Language for Beginers.ppt
Modeling in R Programming Language for Beginers.pptanshikagoel52
 
R programming language
R programming languageR programming language
R programming languageKeerti Verma
 
Unit1_Introduction to R.pdf
Unit1_Introduction to R.pdfUnit1_Introduction to R.pdf
Unit1_Introduction to R.pdfMDDidarulAlam15
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfKabilaArun
 

Similar to R basics for MBA Students[1].pptx (20)

Introduction to R for beginners
Introduction to R for beginnersIntroduction to R for beginners
Introduction to R for beginners
 
Lecture_R.ppt
Lecture_R.pptLecture_R.ppt
Lecture_R.ppt
 
Lecture1
Lecture1Lecture1
Lecture1
 
STAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdf
STAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdfSTAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdf
STAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdf
 
Special topics in finance lecture 2
Special topics in finance   lecture 2Special topics in finance   lecture 2
Special topics in finance lecture 2
 
R programming Language , Rahul Singh
R programming Language , Rahul SinghR programming Language , Rahul Singh
R programming Language , Rahul Singh
 
R programming Language
R programming LanguageR programming Language
R programming Language
 
Statistical Analysis and Data Analysis using R Programming Language: Efficien...
Statistical Analysis and Data Analysis using R Programming Language: Efficien...Statistical Analysis and Data Analysis using R Programming Language: Efficien...
Statistical Analysis and Data Analysis using R Programming Language: Efficien...
 
Unit 3
Unit 3Unit 3
Unit 3
 
Lecture1_R.ppt
Lecture1_R.pptLecture1_R.ppt
Lecture1_R.ppt
 
Lecture1_R.ppt
Lecture1_R.pptLecture1_R.ppt
Lecture1_R.ppt
 
Lecture1 r
Lecture1 rLecture1 r
Lecture1 r
 
Modeling in R Programming Language for Beginers.ppt
Modeling in R Programming Language for Beginers.pptModeling in R Programming Language for Beginers.ppt
Modeling in R Programming Language for Beginers.ppt
 
R programming language
R programming languageR programming language
R programming language
 
Unit1_Introduction to R.pdf
Unit1_Introduction to R.pdfUnit1_Introduction to R.pdf
Unit1_Introduction to R.pdf
 
Data analytics with R
Data analytics with RData analytics with R
Data analytics with R
 
An Intoduction to R
An Intoduction to RAn Intoduction to R
An Intoduction to R
 
Data Mining with R programming
Data Mining with R programmingData Mining with R programming
Data Mining with R programming
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 

More from rajalakshmi5921

Module_-_3_Product_Mgt_&_Pricing[1].pptx
Module_-_3_Product_Mgt_&_Pricing[1].pptxModule_-_3_Product_Mgt_&_Pricing[1].pptx
Module_-_3_Product_Mgt_&_Pricing[1].pptxrajalakshmi5921
 
mental health education for learners.pdf
mental health education for  learners.pdfmental health education for  learners.pdf
mental health education for learners.pdfrajalakshmi5921
 
General Nurses Role in child mental CAP.pptx
General Nurses Role in  child mental CAP.pptxGeneral Nurses Role in  child mental CAP.pptx
General Nurses Role in child mental CAP.pptxrajalakshmi5921
 
Role of Family in Mental Health welbeing.pptx
Role of Family in Mental Health welbeing.pptxRole of Family in Mental Health welbeing.pptx
Role of Family in Mental Health welbeing.pptxrajalakshmi5921
 
Developmental disorders in children .pptx
Developmental disorders in children .pptxDevelopmental disorders in children .pptx
Developmental disorders in children .pptxrajalakshmi5921
 
Bangaluru Water crisis problem solving method.pptx
Bangaluru Water crisis problem solving method.pptxBangaluru Water crisis problem solving method.pptx
Bangaluru Water crisis problem solving method.pptxrajalakshmi5921
 
The efforts made by Karnataka government not enough.pptx
The efforts made by Karnataka government not enough.pptxThe efforts made by Karnataka government not enough.pptx
The efforts made by Karnataka government not enough.pptxrajalakshmi5921
 
business excellence in technology and industry
business excellence in technology and industrybusiness excellence in technology and industry
business excellence in technology and industryrajalakshmi5921
 
employablility training mba mca students to get updated
employablility training mba mca students to get updatedemployablility training mba mca students to get updated
employablility training mba mca students to get updatedrajalakshmi5921
 
EDAB Module 5 Singular Value Decomposition (SVD).pptx
EDAB Module 5 Singular Value Decomposition (SVD).pptxEDAB Module 5 Singular Value Decomposition (SVD).pptx
EDAB Module 5 Singular Value Decomposition (SVD).pptxrajalakshmi5921
 
Support Vector Machines USING MACHINE LEARNING HOW IT WORKS
Support Vector Machines USING MACHINE LEARNING HOW IT WORKSSupport Vector Machines USING MACHINE LEARNING HOW IT WORKS
Support Vector Machines USING MACHINE LEARNING HOW IT WORKSrajalakshmi5921
 
Business Administration Expertise.pptx
Business Administration Expertise.pptxBusiness Administration Expertise.pptx
Business Administration Expertise.pptxrajalakshmi5921
 
employablility training mba mca.pptx
employablility training mba mca.pptxemployablility training mba mca.pptx
employablility training mba mca.pptxrajalakshmi5921
 
Singular Value Decomposition (SVD).pptx
Singular Value Decomposition (SVD).pptxSingular Value Decomposition (SVD).pptx
Singular Value Decomposition (SVD).pptxrajalakshmi5921
 
variableselectionmodelBuilding.ppt
variableselectionmodelBuilding.pptvariableselectionmodelBuilding.ppt
variableselectionmodelBuilding.pptrajalakshmi5921
 
Statistical Learning and Model Selection (1).pptx
Statistical Learning and Model Selection (1).pptxStatistical Learning and Model Selection (1).pptx
Statistical Learning and Model Selection (1).pptxrajalakshmi5921
 
How to obtain and install R.ppt
How to obtain and install R.pptHow to obtain and install R.ppt
How to obtain and install R.pptrajalakshmi5921
 
scm second module ppt.ppt
scm second module ppt.pptscm second module ppt.ppt
scm second module ppt.pptrajalakshmi5921
 
Entrepreneurship Development module I.pptx
Entrepreneurship Development module I.pptxEntrepreneurship Development module I.pptx
Entrepreneurship Development module I.pptxrajalakshmi5921
 

More from rajalakshmi5921 (20)

Module_-_3_Product_Mgt_&_Pricing[1].pptx
Module_-_3_Product_Mgt_&_Pricing[1].pptxModule_-_3_Product_Mgt_&_Pricing[1].pptx
Module_-_3_Product_Mgt_&_Pricing[1].pptx
 
mental health education for learners.pdf
mental health education for  learners.pdfmental health education for  learners.pdf
mental health education for learners.pdf
 
General Nurses Role in child mental CAP.pptx
General Nurses Role in  child mental CAP.pptxGeneral Nurses Role in  child mental CAP.pptx
General Nurses Role in child mental CAP.pptx
 
Role of Family in Mental Health welbeing.pptx
Role of Family in Mental Health welbeing.pptxRole of Family in Mental Health welbeing.pptx
Role of Family in Mental Health welbeing.pptx
 
Developmental disorders in children .pptx
Developmental disorders in children .pptxDevelopmental disorders in children .pptx
Developmental disorders in children .pptx
 
Bangaluru Water crisis problem solving method.pptx
Bangaluru Water crisis problem solving method.pptxBangaluru Water crisis problem solving method.pptx
Bangaluru Water crisis problem solving method.pptx
 
The efforts made by Karnataka government not enough.pptx
The efforts made by Karnataka government not enough.pptxThe efforts made by Karnataka government not enough.pptx
The efforts made by Karnataka government not enough.pptx
 
business excellence in technology and industry
business excellence in technology and industrybusiness excellence in technology and industry
business excellence in technology and industry
 
employablility training mba mca students to get updated
employablility training mba mca students to get updatedemployablility training mba mca students to get updated
employablility training mba mca students to get updated
 
EDAB Module 5 Singular Value Decomposition (SVD).pptx
EDAB Module 5 Singular Value Decomposition (SVD).pptxEDAB Module 5 Singular Value Decomposition (SVD).pptx
EDAB Module 5 Singular Value Decomposition (SVD).pptx
 
Support Vector Machines USING MACHINE LEARNING HOW IT WORKS
Support Vector Machines USING MACHINE LEARNING HOW IT WORKSSupport Vector Machines USING MACHINE LEARNING HOW IT WORKS
Support Vector Machines USING MACHINE LEARNING HOW IT WORKS
 
Business Administration Expertise.pptx
Business Administration Expertise.pptxBusiness Administration Expertise.pptx
Business Administration Expertise.pptx
 
RRCE MBA students.pptx
RRCE MBA students.pptxRRCE MBA students.pptx
RRCE MBA students.pptx
 
employablility training mba mca.pptx
employablility training mba mca.pptxemployablility training mba mca.pptx
employablility training mba mca.pptx
 
Singular Value Decomposition (SVD).pptx
Singular Value Decomposition (SVD).pptxSingular Value Decomposition (SVD).pptx
Singular Value Decomposition (SVD).pptx
 
variableselectionmodelBuilding.ppt
variableselectionmodelBuilding.pptvariableselectionmodelBuilding.ppt
variableselectionmodelBuilding.ppt
 
Statistical Learning and Model Selection (1).pptx
Statistical Learning and Model Selection (1).pptxStatistical Learning and Model Selection (1).pptx
Statistical Learning and Model Selection (1).pptx
 
How to obtain and install R.ppt
How to obtain and install R.pptHow to obtain and install R.ppt
How to obtain and install R.ppt
 
scm second module ppt.ppt
scm second module ppt.pptscm second module ppt.ppt
scm second module ppt.ppt
 
Entrepreneurship Development module I.pptx
Entrepreneurship Development module I.pptxEntrepreneurship Development module I.pptx
Entrepreneurship Development module I.pptx
 

Recently uploaded

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 

Recently uploaded (20)

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 

R basics for MBA Students[1].pptx

  • 2. History and Introduction 2  Ris a programminglanguageand free software environmentfor statistical computing and graphics supported by the R Foundation for Statistical Computing.  R is widely used by statisticians, data analysts and researchers for developing statistical software and data analysis.  It compiles and runs on a wide variety of UNIX platforms, Windows and Mac OS.  The copyright for the primary source code for R is held by the R Foundation and is published under the GNU General Public License version 2.0.
  • 3. History and Introduction 3  R was created by Ross Ihaka and Robert Gentleman at the University of Auckland, New Zealand.  Currently R is developed & maintained by the R DevelopmentCore Team.  The Applications of R programming language includes : 1.Statical Computing 2.Machine Learning 3.Data Science  R can be downloaded and installed from CRAN(Comprehensive R Archive Network) website.  R language is cross platform interoperable and fully portable which means R program that you write on one platformcan be carried out to other platformand run there.(Platform independent)
  • 4. History and Introduction Top Tier companies using R – companies all over the world use R language for statical analysis. These are some of top tier companies that uses R. Company Name Applications Facebook For behavior analysis related to status updates and profile pictures. Google For advertising effectiveness and economic forecasting. Twitter Microsoft For data visualization and semantic clustering Acquired Revolution Rcompany and use it for a variety of purposes. Uber For statistical analysis Airbnb Scale data science. 4
  • 5. 5 Evolution of R R is a dialect of S language…  It means that R is an implementation of the S programming language combined with lexical scoping semantics & inspired by Scheme.  S language was created by John Chambers in 1976 at Bell Labs.  A commercial version of S was offered as S-PLUS starting in 1988. S version1 S version 2 S version 3 S version4
  • 6. 6 Features of R These are the some of important features of R -  Ris a simple, effective and well-developed, programming language which includes conditionals, loops, user defined &recursive functions and input & output facilities.  R provides a large, coherent and integrated collection of tools for data analysis.  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 graphical facilities for data analysis and display either directly at the computer or printing at the papers.
  • 7. 7 Features of R Fast Calculation Extremely Compatible Open Source Cross Platform Support Wide Packages Large Standard Library  Fast Calculation - R can be used to perform complex mathematical and statistical calculations on data objects of a wide variety.  Extreme Compatibility - R is an interpreted language which means that it does not need a compiler to make a program from the code.  Open Source - R is an open-source software environment. You can make improvements and add packages for additional functionalities  Cross Platform Support - R is machine-independent. It supports the cross-platform operation. Therefore, it can be used on many different operating systems.  Wide Packages - CRAN houses more than 10,000 different packages and extensions that help solve all sorts of problems in data science.  Large Standard Library - R can produce static graphics with production qualityvisualizations and has extendedlibraries providing interactive graphic capabilities.
  • 8. 8 Syntax of R Once we have R environment setup, then it’s easy to start our R command prompt by just typing R in command prompt. Hello World Program – >myString <- “Hello world !” >print(myString) The [ ] in the output of R can be used to reference data frame columns Output : [1] “Hello World !” In the Syntax of R we will discuss –  Data Types  Variables  Keywords  Operators  Data Structures
  • 9. Data Types Logical 9 Integer Character Numeric raw Complex DATA TYPES In R there are basically 6 data types – Data Type Examples Integer 2L,5L,8L Numeric 6,2,1,9 Logical true,false,0,1 raw Raw Bytes complex Z=3+7i Character ‘A’ , ”Aditya” , ”AB12”
  • 10. Variables Rules For Naming Variables in R – 1. InR variable name must be a combination of letters, digits, period(.) and underscores. 2. Itmust start with a letter or period(.) and if it starts with period then it period should not be followed by number. 3. Reserved words in R cannot be used in variable name. Valid variables Invalid Variables  myValue  .my.value.one  my_value_one  Data4  .1nikku  TRUE  vik@sh  _temp 10
  • 11. Keywords 11 Reserved Keywords in R – Reserved words are set of words that have special meaning and cannot be used as names of identifiers. If Else Repeat While Function For In Next Break TRUE FALSE NULL inf NaN - Reserved Keywords in R
  • 12. Operators 12 Inany programming language, an operator is a symbol which is used to represent an action. R has several operators to perform tasks including arithmetic, logical and bitwise operations. Operators in R can mainly be classified into the following categories – 1.Arithmetic Operators ={ +, - , *, / , % %, %/%} 2.Logical Operators={! , & , && , | , | | } 3.Assignment operators={< -, < < - , =, ->, ->>} 4.Relational Operators={<, >, < =, > =, !=, = = }
  • 13. Functions Functions are used to incorporate sets of instructions that you want to use repeatedly. There are two types of functions. Function Built In User Defined 13
  • 14. Built - In 14 Built-in functions are those functions which are provided by R so that we can use directly within the language and its standard libraries. In R there are so many built-in functions which make our programming fast and easy. For Example : 1.The sum(a,b) function will return (a+b) >print(sum(10,20)) [1] 30 2.The seq(a,b) function is used to get sequence from a to b. >print(seq(5,15)) [1] 5 6 7 8 9 10 11 12 13 14 15
  • 15. User Defined User defined functions are those functions which we define in our code and use them repeatedly. These functions can be defined with two types. 1.Without Arguments 2.WithArguments Without Arguments With Arguments myFunction <- function() { #This will be printed on calling this funcition print(“Without Arguments”) } myFunction <- function(a,b) { #This function will print sum of passed args print(a+b) }
  • 16. Conditional Statements 16  Conditional Statements in R programming are used to make decisions based on the conditions.  Conditional statements execute sequentially when there is no condition around the statements. In R language we’ll discuss 3 types of Conditional Statements – 1.If - else statements 2. If – else if – else statements 3.Switch statements
  • 17. If-else Start 17 Execute Else block End Execute If Block Condition True? yes no Syntax – If(condition) { expression 1 } Else { expression 2 } Example – If(a>b) { print(“a is greater than b”) } Else { print(“ a is less than b”) }
  • 18. Switch statement 18  Inswitch() function we pass two types of arguments one is value and others is list of items.  The expression is evaluated based on the value and corresponding item is returned.  Ifthe value evaluated from the expression matches with more than one item of the list then switch() function returns the item which was matched first. Examples: > switch(2,”Delhi”,”Jaipur”,”Mumbai”) >[1] “Jaipur” > a=3 > switch(a,”red”,”blue”,”green”,”yellow”) > [1] “green”
  • 19. Loops Loops In R 19 Loops are used When we need to execute particular code repeatedly. 3 types In R Language there are of Loops – 1.For Loop 2.While Loop 3.Repeat Loop
  • 20. For Loop Example to count the number of even numbers in a vector. Program - x <- c(2,5,3,9,8,11,6) count <- 0 for (i in x) { if(i %% 2 == 0) { count=count+1 } } print(count) Output - [1] 3 No Last item Reached?? Body of For Loop Yes For each item in Sequence A for loop is used to iterate over a vector in R programming. Exit Loop 20
  • 21. 21 While Loop i <- 1 while(i<5) { print(i) i=i+1 } Output – [1] 1 [1] 2 [1] 3 [1] 4 Yes No Condition True?? Execute code of while block InR programming, while loops are used to loop until a specific condition is met. Program – Start Execute code outside while block
  • 22. Repeat Loop  A repeat loop is used to iterate over a block of code multiple number of times.  There is no condition check in repeat loop to exit the loop.  We must ourselves put a condition explicitly inside the body of the loop and use the break statement to exit the loop. Failing to do so will result into an infinite loop. Example – x <- 1 repeat { print(x) x = x+1 if (x == 4) { break } } Output – [1] 1 [1] 2 [1] 3 Body of Loop Break ? Remaining body of loop Exit Enter Loop Yes No 22
  • 23. Data Structures 23 DATA STRUCTURES Vectors Factors Data Frames Lists Matrices Arrays A data structure is a particular organizing data in a computer so be used effectively. The idea is way of that it can to reduce the space and time complexities of different tasks. Data structures in R programming are tools for holding multiple values. The most essential data structures used in R include :  Vectors  Arrays  Factors  Lists  Matrices  Data Frames
  • 24. Vector 24  Vector is the one of basic data structure of R which supports integer, double, Character, logical, complex and raw data types.  The elements in a vector are known as components of a vector. V ECTOR CREATION Vector can be created using these two methods :- 1.By Using Colon(:) Operator – a <- 2:8 print(a) # 2 3 4 5 6 7 8 2.By Using seq() function– a <- seq(2,10,by=2) print(a) # 2 4 6 8 10
  • 25. 25 Vector V ECTOR OPERATIONS 1.CombiningVectors a <- c(4,3,5) b <- c(‘x’,’y’,’z’) c <- c(a,b) print(c) o/p= 4 3 5 x y z 2.Arithmetic Operations a <- c(1,2,3) b <- c(4,5,6) d <- a+b print(d) o/p = 5 7 9 3.Numeric Indexing a <- c(4,3,5) Print(a[2]) op = 5 4.DuplicateIndexing a <- c(4,3,5) print(a[1,2,2,3,3]) o/p=4 3 3 5 5 5.LogicalIndexing a <- c(4,3,5) print(a[true,false,true]) o/p = 4 5 6.RangeIndexing a <- c(1,2,3,4,5,6,7) print(a[2:6]) o/p = 2 3 4 5 6
  • 26. 26 Array Arrays allow us to store data in multi - dimensions and use in efficient way. ARRAY CREATION Syntax - Array_Name <- array(data, dim=(row_size,column_size,matrices), dim_names) ARRAY OPERATIONS 1.Accessing Array Elements – Accessing array in R is similar to other programming languages like c,c++ and java. Eg. Print(Arr[2,2]) 2.Arithmetic Operations – Eg. Arr3 <- Arr2 + Arr1 Or Arr3 = Arr1 – Arr2
  • 27. Data Frame 27 Data Frame is a table or a two dimensional Array type structure. Important Considerations  The Column names should be non-empty.  The row names should be unique.  The Data stored in Data Frames can be only Numeric, Factor or Character Type.  Each column should contain same number of data types. Data Frame Creation products <-data.frame( product_number = seq(1:4) product_name = c(“Apple”,”Samsung”,”Redmi”,”Oppo”)) print(products) Product_number Product_name 1 Apple 2 Samsung 3 Redmi 4 Oppo
  • 28. Lists 28  List is a data structure which have components of Mixed data types.  So a vector having elements of different data types is called a list.  List can be created using list() function. Eg. – x <- list( a=“amba”,b=9.23,c=TRUE) #list storing 3 different data types Accessing List Elements print(x[‘b’]) print(x[‘a’]) o/p = 9.23 o/p = “amba” Manipulating List Elements x[‘a’] <- “nitin” print([‘a’]) o/p = “nitin”
  • 29. Matrices 29  In R two dimensional rectangular data set is known as Matrix.  A Matrix is created with the help of the input vector to the matrix() function.  We can Perform addition, subtraction, multiplication and division operations on matrices. Creating matrix - Matrix1 <- matrix (2:7,nrow=2,ncol=3) print(Matrix1) o/p = 2 3 4 6 5 7 Accessing Elements – Matrix1[2,3] # 7 Assigning Value – Matrix1[2,3]=1
  • 30. Matrices 30 Operations On Matrices 1.Addition : Matrix3=Matrix1+Matrix2 2.Subtraction : Matrix3 = Matrix2 – Matrix1 3.Multiply by a Constant : Ex : 7*Matrix1 4.Identity Matrix : Ex – diag(5) 5.Transposition Ex – t(Matrix1)
  • 31. 31 Factors Factors are data objects which are used to categorise the data and store it as levels. For example: a data field such as marital status may contain only values from single, married, separated, divorced, or widowed. >x [1] single married married single Levels : married single Here, we can see that factor x has four elements and two levels. We can check if a variable is a factor or not using class() function. >class(x) [1] “factor” >levels(x) [1] married single
  • 32. R - Studio Interacting with R Studio –  R-Studio is a free and open-source integrated development environment (IDE) for R, a programming language for statistical computing and graphics.  R-Studio was founded by JJ Allaire,creator of the programming language ColdFusion.  There are 4 main sections in R-Studio IDE… 1.Code Editor 2.Workspace and History 3.R console 4.Plots and Files
  • 33. R - Studio 33  RSTUDIO IS AVAILABLE IN TWO EDITIONS: 1.RSTUDIO DESKTOP, WHERE THE PROGRAM IS RUN LOCALLY A S A REGULAR DESKTOP APPLICATION. 2.RSTUDIO SERVER, PREPACKAGED DISTRIBUTIONS OF RSTUDIO DESKTOP ARE AVAILABLE FOR WINDOWS, OS X, AND LINUX.  RSTUDIO IS WRITTEN IN THE C+ + PROGRAMMING LANGUAGE AND USES THE QT FRAMEWORK FOR ITS gRAPHICAL USER INTERFACE.