SlideShare une entreprise Scribd logo
1  sur  9
Télécharger pour lire hors ligne
4/16/2020 R Programming Lab - 1 - Jupyter Notebook
https://hub.gke.mybinder.org/user/binder-examples-r-kagj2wsh/notebooks/R Programming Lab - 1.ipynb 1/9
R - Notebook [LAB EXPERIMENTS DEMONSTRATION] ---------------Prepared by - Asst. Prof.
Ashwini Mathur(CSSP)- Jain University
Following Tasks to Perform:
1. Explore assignment operator.
2. Create vectors using c(), seq(), rep(), colon operator.
3. Create different matrices using matrix() operator and explore its row
s, columns, and diagonals.
4. Perform different basic operation of matrices on above created matric
es.
5. Create single and multidimensional arrays with array() command.
6. Explore length(), dim(), ncol(), nrow() operators on above matrices a
nd arrays.
7. Explore commands for Selecting and extracting elements from above mat
rices and arrays.
8. Explore logical operators from R programming language.
9. Remove elements from selected positions from a considered matrix.
Question -1: Explore Assignments Operators
In [4]:
Question 2. Arithmetic Operators : Addition, Substration, Multiplication and Division
20
30
x = 20 #assigned value to the variable x
x
y = 30 #assigned value to the variable y
y
4/16/2020 R Programming Lab - 1 - Jupyter Notebook
https://hub.gke.mybinder.org/user/binder-examples-r-kagj2wsh/notebooks/R Programming Lab - 1.ipynb 2/9
In [5]:
Create vectors using c(), seq(), rep(), colon operator
In [8]:
Create different matrices using matrix() operator and explore its rows, columns, and
diagonals.
50
-10
600
0.666666666666667
100 200 300 400 500
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10
10 11 12 13 14 15 16 17 18 19 20
50 50 50 50 50 50 50 50 50 50
a = x+y # addition operator
a
b = x-y # substraction operator
b
c = x*y # Multiplication operator
c
d = x/y # Division operator
d
x = c(100,200,300,400,500) #creation of Vector
x #Print x
y = seq(1,10, by=0.5)
y #print y
z = 10:20
z #Print z
q = rep(50,10) #repeat(10 number 10 times)
q #
4/16/2020 R Programming Lab - 1 - Jupyter Notebook
https://hub.gke.mybinder.org/user/binder-examples-r-kagj2wsh/notebooks/R Programming Lab - 1.ipynb 3/9
In [9]:
In [13]:
In [14]:
Perform different basic operation of matrices on above created matrices
A matrix: 4 × 4
of type int
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
A matrix:
3 × 3 of
type int
1 2 3
4 5 6
7 8 9
A matrix:
3 × 3 of
type int
1 4 7
2 5 8
3 6 9
x = matrix(1:16, nrow = 4, ncol = 4) # Create a matrix of dimension 3X3
x
y = matrix(1:9, nrow=3, byrow=TRUE) # fill matrix row-wise
y
z = matrix(1:9, nrow=3, byrow=FALSE) # fill matrix column-wise
z
4/16/2020 R Programming Lab - 1 - Jupyter Notebook
https://hub.gke.mybinder.org/user/binder-examples-r-kagj2wsh/notebooks/R Programming Lab - 1.ipynb 4/9
In [16]:
In [17]:
Create single and multidimensional arrays with array() command
In [18]:
A
matrix:
3 × 2
of type
dbl
1 4
2 5
3 6
3 2
A matrix:
2 × 3 of
type dbl
1 2 3
4 5 6
2 3
2 9 3
10 16 17 13 11 15
x = cbind(c(1,2,3),c(4,5,6))
x
dim(x)
y = rbind(c(1,2,3),c(4,5,6))
y
dim(y)
# Create two vectors of different lengths.
vector1 <- c(2,9,3)
vector2 <- c(10,16,17,13,11,15)
vector1 #print
vector2
4/16/2020 R Programming Lab - 1 - Jupyter Notebook
https://hub.gke.mybinder.org/user/binder-examples-r-kagj2wsh/notebooks/R Programming Lab - 1.ipynb 5/9
In [25]:
In [ ]:
Explore length(), dim(), ncol(), nrow() operators on above matrices and arrays.
, , 1
[,1] [,2] [,3]
[1,] 2 10 13
[2,] 9 16 11
[3,] 3 17 15
, , 2
[,1] [,2] [,3]
[1,] 2 10 13
[2,] 9 16 11
[3,] 3 17 15
# Take these vectors as input to the array.
result <- array(c(vector1,vector2),dim = c(3,3,2)) #Multi-dimension
print(result)
result <- array(c(vector1,vector2),dim = c(3)) #Single dimension
print(result)
4/16/2020 R Programming Lab - 1 - Jupyter Notebook
https://hub.gke.mybinder.org/user/binder-examples-r-kagj2wsh/notebooks/R Programming Lab - 1.ipynb 6/9
In [19]:
In [ ]:
Explore commands for Selecting and extracting elements from above matrices and arrays.
In [21]:
A matrix: 10 × 10 of type int
1 11 21 31 41 51 61 71 81 91
2 12 22 32 42 52 62 72 82 92
3 13 23 33 43 53 63 73 83 93
4 14 24 34 44 54 64 74 84 94
5 15 25 35 45 55 65 75 85 95
6 16 26 36 46 56 66 76 86 96
7 17 27 37 47 57 67 77 87 97
8 18 28 38 48 58 68 78 88 98
9 19 29 39 49 59 69 79 89 99
10 20 30 40 50 60 70 80 90 100
100
10 10
A matrix:
3 × 3 of
type int
1 4 7
2 5 8
3 6 9
4
x = matrix(1:100, nrow = 10, ncol = 10)
x
length(x) #Length of the Matrix
dim(x) #Dimension of the given matrix
ncol(x) #Total number of columns in given matrix
nrow(x) #Total Number of Rows in Given Matrix
x = matrix(1:9, nrow = 3, ncol = 3)
x
x[1,2] #Selecting the element of First row and second column
4/16/2020 R Programming Lab - 1 - Jupyter Notebook
https://hub.gke.mybinder.org/user/binder-examples-r-kagj2wsh/notebooks/R Programming Lab - 1.ipynb 7/9
In [22]:
In [30]:
In [23]:
In [32]:
Explore logical operators from R programming language.
In [33]:
In [34]:
In [35]:
In [36]:
9
1 2 3
2 5 8
13
10
FALSE TRUE TRUE FALSE
FALSE FALSE FALSE TRUE
FALSE
TRUE TRUE FALSE TRUE
x[3,3] #Selecting the element of third row and third column
x[,1] #Selection the 1st column
x[2,] #Selecting the 3rd row
y <- c(10,16,17,13,11,15)
y[4] #Selecting 4th element
y[1] #selecting the first element
x <- c(TRUE,FALSE,0,6)
y <- c(FALSE,TRUE,FALSE,TRUE)
!x #(Complement of x) Logical NOT
x&y #Element-wise logical AND
x&&y #Logical AND
x|y # Element Wise Logical OR
4/16/2020 R Programming Lab - 1 - Jupyter Notebook
https://hub.gke.mybinder.org/user/binder-examples-r-kagj2wsh/notebooks/R Programming Lab - 1.ipynb 8/9
In [37]:
Remove elements from selected positions from a considered matrix.
In [38]:
In [39]:
TRUE
A matrix:
3 × 3 of
type int
1 4 7
2 5 8
3 6 9
A
matrix:
3 × 2
of type
int
1 4
2 5
3 6
A matrix:
3 × 3 of
type int
1 4 7
2 5 8
3 6 9
x||y #Logical OR
x = matrix(1:9, nrow = 3, ncol = 3)
x
x[,-3] #Remove 3rd Column
4/16/2020 R Programming Lab - 1 - Jupyter Notebook
https://hub.gke.mybinder.org/user/binder-examples-r-kagj2wsh/notebooks/R Programming Lab - 1.ipynb 9/9
In [40]:
A matrix:
2 × 3 of
type int
1 4 7
2 5 8
x[-3,] #Remove 3rd Row

Contenu connexe

Tendances

computer notes - Data Structures - 9
computer notes - Data Structures - 9computer notes - Data Structures - 9
computer notes - Data Structures - 9
ecomputernotes
 
〇〇の常識は■■の非常識
〇〇の常識は■■の非常識〇〇の常識は■■の非常識
〇〇の常識は■■の非常識
Yoichi Hirai
 

Tendances (20)

Metaprogramming
MetaprogrammingMetaprogramming
Metaprogramming
 
Dynamic allocation
Dynamic allocationDynamic allocation
Dynamic allocation
 
Sample2
Sample2Sample2
Sample2
 
Lecture 1 mte 407
Lecture 1 mte 407Lecture 1 mte 407
Lecture 1 mte 407
 
Lecture 1 mte 407
Lecture 1 mte 407Lecture 1 mte 407
Lecture 1 mte 407
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
 
CLASS XII COMPUTER SCIENCE MONTHLY TEST PAPER
CLASS XII COMPUTER SCIENCE MONTHLY TEST  PAPERCLASS XII COMPUTER SCIENCE MONTHLY TEST  PAPER
CLASS XII COMPUTER SCIENCE MONTHLY TEST PAPER
 
The matplotlib Library
The matplotlib LibraryThe matplotlib Library
The matplotlib Library
 
Seminar fp
Seminar fpSeminar fp
Seminar fp
 
Heap sort &amp; bubble sort
Heap sort &amp; bubble sortHeap sort &amp; bubble sort
Heap sort &amp; bubble sort
 
Wcbpijwbpij new
Wcbpijwbpij newWcbpijwbpij new
Wcbpijwbpij new
 
Py9 3
Py9 3Py9 3
Py9 3
 
QMC: Undergraduate Workshop, Tutorial on 'R' Software - Yawen Guan, Feb 26, 2...
QMC: Undergraduate Workshop, Tutorial on 'R' Software - Yawen Guan, Feb 26, 2...QMC: Undergraduate Workshop, Tutorial on 'R' Software - Yawen Guan, Feb 26, 2...
QMC: Undergraduate Workshop, Tutorial on 'R' Software - Yawen Guan, Feb 26, 2...
 
computer notes - Data Structures - 9
computer notes - Data Structures - 9computer notes - Data Structures - 9
computer notes - Data Structures - 9
 
Tensorflow basics
Tensorflow basicsTensorflow basics
Tensorflow basics
 
〇〇の常識は■■の非常識
〇〇の常識は■■の非常識〇〇の常識は■■の非常識
〇〇の常識は■■の非常識
 
Matplotlib
MatplotlibMatplotlib
Matplotlib
 
Dynamic Memory allocation
Dynamic Memory allocationDynamic Memory allocation
Dynamic Memory allocation
 
Chapter 1 Basic Concepts
Chapter 1 Basic ConceptsChapter 1 Basic Concepts
Chapter 1 Basic Concepts
 
Ss matlab solved
Ss matlab solvedSs matlab solved
Ss matlab solved
 

Similaire à R programming lab 1 - jupyter notebook

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
anshikagoel52
 

Similaire à R programming lab 1 - jupyter notebook (20)

Introduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordIntroduction to Data Science With R Lab Record
Introduction to Data Science With R Lab Record
 
R tutorial for a windows environment
R tutorial for a windows environmentR tutorial for a windows environment
R tutorial for a windows environment
 
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
 
R basics
R basicsR basics
R basics
 
A practical work of matlab
A practical work of matlabA practical work of matlab
A practical work of matlab
 
R Programming Intro
R Programming IntroR Programming Intro
R Programming Intro
 
2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors
 
Computer Science CS Project Matrix CBSE Class 12th XII .pdf
Computer Science CS Project Matrix CBSE Class 12th XII .pdfComputer Science CS Project Matrix CBSE Class 12th XII .pdf
Computer Science CS Project Matrix CBSE Class 12th XII .pdf
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 
Data Structures problems 2002
Data Structures problems 2002Data Structures problems 2002
Data Structures problems 2002
 
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
 
Informatics Practices (new) solution CBSE 2021, Compartment, improvement ex...
Informatics Practices (new) solution CBSE  2021, Compartment,  improvement ex...Informatics Practices (new) solution CBSE  2021, Compartment,  improvement ex...
Informatics Practices (new) solution CBSE 2021, Compartment, improvement ex...
 
RDataMining slides-r-programming
RDataMining slides-r-programmingRDataMining slides-r-programming
RDataMining slides-r-programming
 
C sharp chap6
C sharp chap6C sharp chap6
C sharp chap6
 
R programming lab 3 - jupyter notebook
R programming lab   3 - jupyter notebookR programming lab   3 - jupyter notebook
R programming lab 3 - jupyter notebook
 
CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017
CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017
CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017
 
Mmc manual
Mmc manualMmc manual
Mmc manual
 

Plus de Ashwini Mathur

Linear programming optimization in r
Linear programming optimization in r Linear programming optimization in r
Linear programming optimization in r
Ashwini Mathur
 
Introduction to python along with the comparitive analysis with r
Introduction to python   along with the comparitive analysis with r Introduction to python   along with the comparitive analysis with r
Introduction to python along with the comparitive analysis with r
Ashwini Mathur
 
Example 2 summerization notes for descriptive statistics using r
Example   2    summerization notes for descriptive statistics using r Example   2    summerization notes for descriptive statistics using r
Example 2 summerization notes for descriptive statistics using r
Ashwini Mathur
 
Descriptive analytics in r programming language
Descriptive analytics in r programming languageDescriptive analytics in r programming language
Descriptive analytics in r programming language
Ashwini Mathur
 

Plus de Ashwini Mathur (18)

S3 classes and s4 classes
S3 classes and s4 classesS3 classes and s4 classes
S3 classes and s4 classes
 
Summerization notes for descriptive statistics using r
Summerization notes for descriptive statistics using r Summerization notes for descriptive statistics using r
Summerization notes for descriptive statistics using r
 
Rpy2 demonstration
Rpy2 demonstrationRpy2 demonstration
Rpy2 demonstration
 
Rpy package
Rpy packageRpy package
Rpy package
 
R programming lab 2 - jupyter notebook
R programming lab   2 - jupyter notebookR programming lab   2 - jupyter notebook
R programming lab 2 - jupyter notebook
 
R for statistics session 1
R for statistics session 1R for statistics session 1
R for statistics session 1
 
R for statistics 2
R for statistics 2R for statistics 2
R for statistics 2
 
Play with matrix in r
Play with matrix in rPlay with matrix in r
Play with matrix in r
 
Object oriented programming in r
Object oriented programming in r Object oriented programming in r
Object oriented programming in r
 
Linear programming optimization in r
Linear programming optimization in r Linear programming optimization in r
Linear programming optimization in r
 
Introduction to python along with the comparitive analysis with r
Introduction to python   along with the comparitive analysis with r Introduction to python   along with the comparitive analysis with r
Introduction to python along with the comparitive analysis with r
 
Example 2 summerization notes for descriptive statistics using r
Example   2    summerization notes for descriptive statistics using r Example   2    summerization notes for descriptive statistics using r
Example 2 summerization notes for descriptive statistics using r
 
Descriptive statistics assignment
Descriptive statistics assignment Descriptive statistics assignment
Descriptive statistics assignment
 
Descriptive analytics in r programming language
Descriptive analytics in r programming languageDescriptive analytics in r programming language
Descriptive analytics in r programming language
 
Data analysis for covid 19
Data analysis for covid 19Data analysis for covid 19
Data analysis for covid 19
 
Correlation and linear regression
Correlation and linear regression Correlation and linear regression
Correlation and linear regression
 
Calling c functions from r programming unit 5
Calling c functions from r programming    unit 5Calling c functions from r programming    unit 5
Calling c functions from r programming unit 5
 
Anova (analysis of variance) test
Anova (analysis of variance) test Anova (analysis of variance) test
Anova (analysis of variance) test
 

Dernier

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 

Dernier (20)

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 

R programming lab 1 - jupyter notebook

  • 1. 4/16/2020 R Programming Lab - 1 - Jupyter Notebook https://hub.gke.mybinder.org/user/binder-examples-r-kagj2wsh/notebooks/R Programming Lab - 1.ipynb 1/9 R - Notebook [LAB EXPERIMENTS DEMONSTRATION] ---------------Prepared by - Asst. Prof. Ashwini Mathur(CSSP)- Jain University Following Tasks to Perform: 1. Explore assignment operator. 2. Create vectors using c(), seq(), rep(), colon operator. 3. Create different matrices using matrix() operator and explore its row s, columns, and diagonals. 4. Perform different basic operation of matrices on above created matric es. 5. Create single and multidimensional arrays with array() command. 6. Explore length(), dim(), ncol(), nrow() operators on above matrices a nd arrays. 7. Explore commands for Selecting and extracting elements from above mat rices and arrays. 8. Explore logical operators from R programming language. 9. Remove elements from selected positions from a considered matrix. Question -1: Explore Assignments Operators In [4]: Question 2. Arithmetic Operators : Addition, Substration, Multiplication and Division 20 30 x = 20 #assigned value to the variable x x y = 30 #assigned value to the variable y y
  • 2. 4/16/2020 R Programming Lab - 1 - Jupyter Notebook https://hub.gke.mybinder.org/user/binder-examples-r-kagj2wsh/notebooks/R Programming Lab - 1.ipynb 2/9 In [5]: Create vectors using c(), seq(), rep(), colon operator In [8]: Create different matrices using matrix() operator and explore its rows, columns, and diagonals. 50 -10 600 0.666666666666667 100 200 300 400 500 1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10 10 11 12 13 14 15 16 17 18 19 20 50 50 50 50 50 50 50 50 50 50 a = x+y # addition operator a b = x-y # substraction operator b c = x*y # Multiplication operator c d = x/y # Division operator d x = c(100,200,300,400,500) #creation of Vector x #Print x y = seq(1,10, by=0.5) y #print y z = 10:20 z #Print z q = rep(50,10) #repeat(10 number 10 times) q #
  • 3. 4/16/2020 R Programming Lab - 1 - Jupyter Notebook https://hub.gke.mybinder.org/user/binder-examples-r-kagj2wsh/notebooks/R Programming Lab - 1.ipynb 3/9 In [9]: In [13]: In [14]: Perform different basic operation of matrices on above created matrices A matrix: 4 × 4 of type int 1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16 A matrix: 3 × 3 of type int 1 2 3 4 5 6 7 8 9 A matrix: 3 × 3 of type int 1 4 7 2 5 8 3 6 9 x = matrix(1:16, nrow = 4, ncol = 4) # Create a matrix of dimension 3X3 x y = matrix(1:9, nrow=3, byrow=TRUE) # fill matrix row-wise y z = matrix(1:9, nrow=3, byrow=FALSE) # fill matrix column-wise z
  • 4. 4/16/2020 R Programming Lab - 1 - Jupyter Notebook https://hub.gke.mybinder.org/user/binder-examples-r-kagj2wsh/notebooks/R Programming Lab - 1.ipynb 4/9 In [16]: In [17]: Create single and multidimensional arrays with array() command In [18]: A matrix: 3 × 2 of type dbl 1 4 2 5 3 6 3 2 A matrix: 2 × 3 of type dbl 1 2 3 4 5 6 2 3 2 9 3 10 16 17 13 11 15 x = cbind(c(1,2,3),c(4,5,6)) x dim(x) y = rbind(c(1,2,3),c(4,5,6)) y dim(y) # Create two vectors of different lengths. vector1 <- c(2,9,3) vector2 <- c(10,16,17,13,11,15) vector1 #print vector2
  • 5. 4/16/2020 R Programming Lab - 1 - Jupyter Notebook https://hub.gke.mybinder.org/user/binder-examples-r-kagj2wsh/notebooks/R Programming Lab - 1.ipynb 5/9 In [25]: In [ ]: Explore length(), dim(), ncol(), nrow() operators on above matrices and arrays. , , 1 [,1] [,2] [,3] [1,] 2 10 13 [2,] 9 16 11 [3,] 3 17 15 , , 2 [,1] [,2] [,3] [1,] 2 10 13 [2,] 9 16 11 [3,] 3 17 15 # Take these vectors as input to the array. result <- array(c(vector1,vector2),dim = c(3,3,2)) #Multi-dimension print(result) result <- array(c(vector1,vector2),dim = c(3)) #Single dimension print(result)
  • 6. 4/16/2020 R Programming Lab - 1 - Jupyter Notebook https://hub.gke.mybinder.org/user/binder-examples-r-kagj2wsh/notebooks/R Programming Lab - 1.ipynb 6/9 In [19]: In [ ]: Explore commands for Selecting and extracting elements from above matrices and arrays. In [21]: A matrix: 10 × 10 of type int 1 11 21 31 41 51 61 71 81 91 2 12 22 32 42 52 62 72 82 92 3 13 23 33 43 53 63 73 83 93 4 14 24 34 44 54 64 74 84 94 5 15 25 35 45 55 65 75 85 95 6 16 26 36 46 56 66 76 86 96 7 17 27 37 47 57 67 77 87 97 8 18 28 38 48 58 68 78 88 98 9 19 29 39 49 59 69 79 89 99 10 20 30 40 50 60 70 80 90 100 100 10 10 A matrix: 3 × 3 of type int 1 4 7 2 5 8 3 6 9 4 x = matrix(1:100, nrow = 10, ncol = 10) x length(x) #Length of the Matrix dim(x) #Dimension of the given matrix ncol(x) #Total number of columns in given matrix nrow(x) #Total Number of Rows in Given Matrix x = matrix(1:9, nrow = 3, ncol = 3) x x[1,2] #Selecting the element of First row and second column
  • 7. 4/16/2020 R Programming Lab - 1 - Jupyter Notebook https://hub.gke.mybinder.org/user/binder-examples-r-kagj2wsh/notebooks/R Programming Lab - 1.ipynb 7/9 In [22]: In [30]: In [23]: In [32]: Explore logical operators from R programming language. In [33]: In [34]: In [35]: In [36]: 9 1 2 3 2 5 8 13 10 FALSE TRUE TRUE FALSE FALSE FALSE FALSE TRUE FALSE TRUE TRUE FALSE TRUE x[3,3] #Selecting the element of third row and third column x[,1] #Selection the 1st column x[2,] #Selecting the 3rd row y <- c(10,16,17,13,11,15) y[4] #Selecting 4th element y[1] #selecting the first element x <- c(TRUE,FALSE,0,6) y <- c(FALSE,TRUE,FALSE,TRUE) !x #(Complement of x) Logical NOT x&y #Element-wise logical AND x&&y #Logical AND x|y # Element Wise Logical OR
  • 8. 4/16/2020 R Programming Lab - 1 - Jupyter Notebook https://hub.gke.mybinder.org/user/binder-examples-r-kagj2wsh/notebooks/R Programming Lab - 1.ipynb 8/9 In [37]: Remove elements from selected positions from a considered matrix. In [38]: In [39]: TRUE A matrix: 3 × 3 of type int 1 4 7 2 5 8 3 6 9 A matrix: 3 × 2 of type int 1 4 2 5 3 6 A matrix: 3 × 3 of type int 1 4 7 2 5 8 3 6 9 x||y #Logical OR x = matrix(1:9, nrow = 3, ncol = 3) x x[,-3] #Remove 3rd Column
  • 9. 4/16/2020 R Programming Lab - 1 - Jupyter Notebook https://hub.gke.mybinder.org/user/binder-examples-r-kagj2wsh/notebooks/R Programming Lab - 1.ipynb 9/9 In [40]: A matrix: 2 × 3 of type int 1 4 7 2 5 8 x[-3,] #Remove 3rd Row