0% found this document useful (0 votes)
58 views

R Programming: Presentation by Mrs.S.Jansi Rani, AP (SR - GR) Department of Information Technology

This document provides information about R Programming presented by Mrs. S. Jansi Rani from the Department of Information Technology at SRI RAMAKRISHNA ENGINEERING COLLEGE. It discusses installing R and R Studio, the history of R, comparisons to other languages like Python, features of R programming, applications of R, and basic experiments in R like comments, variables, data types, vectors, and lists. The document aims to introduce the fundamentals of R programming.

Uploaded by

jansi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

R Programming: Presentation by Mrs.S.Jansi Rani, AP (SR - GR) Department of Information Technology

This document provides information about R Programming presented by Mrs. S. Jansi Rani from the Department of Information Technology at SRI RAMAKRISHNA ENGINEERING COLLEGE. It discusses installing R and R Studio, the history of R, comparisons to other languages like Python, features of R programming, applications of R, and basic experiments in R like comments, variables, data types, vectors, and lists. The document aims to introduce the fundamentals of R programming.

Uploaded by

jansi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

SRI RAMAKRISHNA ENGINEERING COLLEGE

[Educational Service : SNR Sons Charitable Trust]


[Autonomous Institution, Accredited by NAAC with ‘A’ Grade]
[Approved by AICTE and Permanently Affiliated to Anna University, Chennai]
[ISO 9001:2015 Certified and all eligible programmes Accredited by NBA]
VATTAMALAIPALAYAM, N.G.G.O. COLONY POST, COIMBATORE – 641 022.

R PROGRAMMING
Presentation By
Mrs.S.Jansi Rani, AP(Sr.Gr)
Department of Information Technology
ACKNOWLEDGEMENT
 Materials: R Programming Related Internet Resources

R Programming 01/18/2021 2
INSTALLING R AND R STUDIO
 R is freely downloadable from http://cran.r-project.org/

 R for windows is freely downloadable from https://cran.r-project.org/bin/windows/base/

 Rstudio – downloadable from https://rstudio.com/products/rstudio/download/#download

R Programming 01/18/2021 3
HISTORY
 R is an implementation of S programming language

 R was created by Ross Ihaka and Robert Gentleman at the university of Auckland, New Zealand

 The project was conceived in 1992, with an initial version released in 1995 and a stable beta version in 2000

 Another stable released on October 31st 2014, by R Development Core Team under GNU General Public

License.

R Programming 01/18/2021 4
COMPARISON WITH OTHER
LANGUAGE
R Programming Python

• Stable Version : 2014 • Stable Version: 1996

• It has more functions and packages • It has less functions and packages

• It is an interpreter base language • It is an interpreter base language

• R is mostly use for data analysis • Generic programming tasks such as design of software’s

• It is difficult to learn and understand • It is easy to understand

R Programming 01/18/2021 5
FEATURES OF R
PROGRAMMING
 It is a simple and effective programming language which has been well developed.

 It is data analysis software.

 It is a well-designed, easy, and effective language which has the concepts of user-defined, looping, conditional, and various I/O facilities.

 It has a consistent and incorporated set of tools which are used for data analysis.

 For different types of calculation on arrays, lists and vectors, R contains a suite of operators.

 It provides effective data handling and storage facility.

 It is an open-source, powerful, and highly extensible software.

 It provides highly extensible graphical techniques.

 It allows us to perform multiple calculations using vectors.

 R is an interpreted language.

R Programming 01/18/2021 6
APPLICATIONS
 Who uses R in their business:

R Programming 01/18/2021 7
INSTALLATION OF R

 R is an outstanding software for general computation, especially


suitable for statistical computing
 Alternative to SPSS
 Free and Open source software
 Download from http://cran.r-project.org/

R Programming 01/18/2021 8
INSTALLATION OF R STUDIO
 R studio is a user friendly front-end for R
 Free and open source
 Download from: http://www.rstudio.com/

R Programming 01/18/2021 9
RSTUDIO IDE
 All the experiments going to work with the help of RStudio IDE.

Console Window

R Programming 01/18/2021 10
BASIC EXPERIMENTS
“Hello World” Program:
Syntax:
> string1<-"hello world"
> string1
[1] "hello world"
> print(string1)
[1] "hello world"

R Programming 01/18/2021 11
COMMENTS
Syntax:
> # First Program
> a=3
> print(a)
[1] 3
The above is an example for Single-line comment

Syntax:
> if(FALSE){"this is trick for multi-line comment"}
> string<-"Welcome to SREC"
> string
[1] "Welcome to SREC"
R doesnot support multi- line comment. So, we have a above trick to implement
multi-line comment

R Programming 01/18/2021 12
VARIABLES IN R
 Variable are nothing but reserved memory locations to store values. This means that when you create a variable

you reserve some space in memory.

R Programming 01/18/2021 13
ASSIGNMENT OF VARIABLE
 Three operators used to assign the values to the variable.

 Leftward (e.g:- a<-2)

 Rightward (e.g:- 2->a)

 equal_to (e.g:- a=2)


> a=2
> a
[1] 2
> a<-2
> a
[1] 2
> 2->a
> a
[1] 2

R Programming 01/18/2021 14
DATA OPERATORS IN R
1. Arithmetic Operator

2. Assignment Operators

3. Relational Operators

4. Logical Operators

5. Special Operators

R Programming 01/18/2021 15
ARITHMETIC OPERATORS
a=2
> b=3
> a+b
[1] 5
> a-b
[1] -1
> a*b
[1] 6
> a/b
[1] 0.6666667
> a^b
[1] 8
> 5%%2
[1] 1
> 2%%2
[1] 0
> 5%/%2
[1] 2
> 7%/%2
[1] 3

R Programming 01/18/2021 16
ASSIGNMENT OPERATORS
> x=2
> x<-3
> y<<-5
>Y
Error: object 'Y' not found
> 3->z
>z
[1] 3

R Programming 01/18/2021 17
RELATIONAL OPERATOR
2>3
[1] FALSE
> 2<3
[1] TRUE
> 2==3
[1] FALSE
> 2==2
[1] TRUE
> 2!=2
[1] FALSE
> 2>=3
[1] FALSE
> 4>=3
[1] TRUE
> 2<=3
[1] TRUE
> 4<=3
[1] FALSE

R Programming 01/18/2021 18
LOGICAL OPERATOR x<-TRUE
>x
[1] TRUE
> !x
[1] FALSE
> Y<- FALSE
> x&y
[1] TRUE
> x&Y
[1] FALSE
> x|Y
[1] TRUE
# Zero is considered FALSE and non-zero numbers are taken as TRUE
2&3
[1] TRUE
> 3&3
[1] TRUE
> x<-3
> y<-4
> z<-3
> x&z
[1] TRUE
R Programming 01/18/2021 19
SPECIAL OPERATORS
x<-2:5
>x
[1] 2 3 4 5
> x[1]
[1] 2
> x[0]
integer(0)
> y=3
> y%in%x
[1] TRUE

R Programming 01/18/2021 20
CHECK & ANSWER
 X<- 2:8
 Y<- 3:4
 X+Y
 X+Y->Z
Z
 X<-1:4
 X>2
 log(-1)

R Programming 01/18/2021 21
DATATYPE
 Note: We do not need to declare a variable before using them.

Data type

Data
Vectors Lists Matrices Array Factors
Frames

R Programming 01/18/2021 22
VECTORS
 A vector is a sequence of data elements of the same basic type

 There are 5 atomic vectors, also termed as five classes of vectors

‘a’,”Hai”,’TRUE’ True, False


Character Logical

Vectors 2,4,3
3+4i Complex Numeric

Integer
R Programming 2L,3L,4L 01/18/2021 23
VECTOR OPERATIONS

list1 <- c('a','b','c')


> list1
[1] "a" "b" "c"
> list1[1]
[1] "a"
> list1[4] <- 'd'
> list1
[1] "a" "b" "c" "d"
> list1[2:4]
[1] "b" "c" "d"
> list1[5] <- 'a'
> list1
[1] "a" "b" "c" "d" "a"
> sort(list1)
[1] "a" "a" "b" "c" "d"

R Programming 01/18/2021 24
LISTS
 List are the R objects which contain elements of different types like –
numbers, strings, vectors and another list inside it.
>> aa <-
<- c(1,2)
c(1,2)
>> bb <-
<- c('a','b')
c('a','b')
>> cc <-
<- list(a,b,TRUE)
list(a,b,TRUE)
>> cc
[[1]]
[[1]]
[1]
[1] 11 22
[[2]]
[[2]]
[1]
[1] "a"
"a" "b"
"b"
[[3]]
[[3]]
[1]
[1] TRUE
TRUE

R Programming 01/18/2021 25
> list1 <- list(1,2,3)
> list2 <- list('a','b',TRUE)

LISTS OPERATIONS
> mergelist <- c(list1,list2)
> mergelist
[[1]]
[1] 1

[[2]]
[1] 2

[[3]]
[1] 3

[[4]]
[1] "a"

[[5]]
[1] "b"

[[6]]
[1] TRUE

> list1[2]
[[1]]
[1] 2
> mergelist[2]
[[1]]
[1] 2
> list3 <- list(list1,list2)
> list3[2]
[[1]]
[[1]][[1]]
[1] "a"
[[1]][[2]]
[1] "b"
[[1]][[3]]
R Programming [1] TRUE 01/18/2021 26
DIFFERENCE
Vectors Lists

Vector stores elements of the same type or A list holds different data such as Numeric,
converts implicitly Character, Logical, etc

Vector is not recursive List are recursive

The vector is one-dimensional The list is a multidimensional object

R Programming 01/18/2021 27
ARRAYS
>> vector1
vector1 <-
<- c(1,2,3)
c(1,2,3)
>> vector2
vector2 <- c(4,5,6,7,8,9)
<- c(4,5,6,7,8,9)
>> result
result <-
<- array(c(vector1,vector2),
array(c(vector1,vector2), dim=c(3,2,
dim=c(3,2,
2))
2))
>> result
result
,, ,, 11
 Arrays are the R data objects which [,1]
[,1] [,2]
[,2]
[1,]
[1,] 11 44
[2,] 22 55
can store data in more than two [2,]
[3,]
[3,] 33 66
,, ,, 22
dimensions
[,1]
[,1] [,2]
[,2]
[1,]
[1,] 77 11
[2,] 88 22
 It takes vectors as input and uses the [2,]
[3,]
[3,] 99 33
>> mat1
mat1 <-
<- array(c(1,2,3,4),dim=c(2,2))
values in the dim parameter to >> mat1
mat1
array(c(1,2,3,4),dim=c(2,2))
[,1]
[,1] [,2]
[,2]
[1,] 11 33
create an array [1,]
[2,]
[2,] 22 44
>> mat1
mat1 <-
<- array(c(1,2,3,4),dim=c(2,2,2))
array(c(1,2,3,4),dim=c(2,2,2))
>> mat1
mat1
,, ,, 11
 E,g:- We create an array of
[,1]
[,1] [,2]
[,2]
[1,] 11 33
dimension (2,3,3), then it creates 3 [1,]
[2,]
[2,] 22 44
,, ,, 22
rectangular matrices each with 2
[,1]
[,1] [,2]
[,2]
[1,]
[1,] 11 33
rows and 3 columns [2,]
[2,] 22 44

R Programming 01/18/2021 28

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy