SlideShare a Scribd company logo
Vector Maths
Arithmetic operations of vectors are performed member-by-member, i.e., member wise.
For example, suppose we have two vectors a and b.
> a = c(1, 3, 5, 7)
> b = c(1, 2, 4, 8)
Then, if we multiply a by 5, we would get a vector with each of its members multiplied by
5.
> 5 * a
[1] 5 15 25 35
And if we add a and b together, the sum would be a vector whose members are the sum
of the corresponding members from a and b.
> a + b
[1] 2 5 9 15
Similarly for subtraction, multiplication and division, we get new vectors via memberwise
operations.
> a - b
[1] 0 1 1 -1
> a * b
[1] 1 6 20 56
> a / b
[1] 1.000 1.500 1.250 0.875
Recycling Rule
• If two vectors are of unequal length, the shorter
one will be recycled in order to match the longer
vector. For example, the following
vectors u and v have different lengths, and their
sum is computed by recycling values of the
shorter vector u.
• > u = c(10, 20, 30)
> v = c(1, 2, 3, 4, 5, 6, 7, 8, 9)
> u + v
[1] 11 22 33 14 25 36 17 28 39
Vector Index
• Vector Index
• We retrieve values in a vector by declaring an
index inside a single square
bracket "[]" operator.
• For example, the following shows how to
retrieve a vector member. Since the vector
index is 1-based, we use the index position 3 for
retrieving the third member.
• > s = c("aa", "bb", "cc", "dd", "ee")
> s[3]
[1] "cc"
Negative Index
• If the index is negative, it would strip the member
whose position has the same absolute value as
the negative index.
• For example, the following creates a vector slice
with the third member removed.
• > s[-3]
[1] "aa" "bb" "dd" "ee"
• Out-of-Range Index
• If an index is out-of-range, a missing value will be
reported via the symbol NA.
• > s[10]
[1] NA
Matrix
• A matrix is a collection of data elements
arranged in a two-dimensional rectangular
layout. The following is an example of a matrix
with 2 rows and 3 columns.
• We reproduce a memory representation of the
matrix in R with the matrix function. The data
elements must be of the same basic type.
• > A = matrix(
+ c(2, 4, 3, 1, 5, 7), # the data elements
+ nrow=2, # number of rows
+ ncol=3, # number of columns
+ byrow = T
• A # print the matrix
[,1] [,2] [,3]
[1,] 2 4 3
[2,] 1 5 7RUE) # fill matrix by rows
• An element at the mth row, nth column of A can be
accessed by the expression A[m, n].
• > A[2, 3] # element at 2nd row, 3rd column
[1] 7
• The entire mth row A can be extracted as A[m, ].
• > A[2, ] # the 2nd row
[1] 1 5 7
• Similarly, the entire nth column A can be extracted as A[
,n].
• > A[ ,3] # the 3rd column
[1] 3 7
• We can also extract more than one rows or columns at a
time.
• > A[ ,c(1,3)] # the 1st and 3rd columns
[,1] [,2]
[1,] 2 3
[2,] 1 7
Matrix Addition & Subtraction
• # Create two 2x3 matrices.
• matrix1 <- matrix(c(3, 9, -1, 4, 2, 6), nrow = 2)
print(matrix1)
• matrix2 <- matrix(c(5, 2, 0, 9, 3, 4), nrow = 2)
print(matrix2)
• # Add the matrices.
• result <- matrix1 + matrix2
• cat("Result of addition","n")
• print(result)
• # Subtract the matrices
• result <- matrix1 - matrix2
• cat("Result of subtraction","n") print(result)
Matrix Multiplication & Division
• # Create two 2x3 matrices.
• matrix1 <- matrix(c(3, 9, -1, 4, 2, 6), nrow = 2)
print(matrix1)
• matrix2 <- matrix(c(5, 2, 0, 9, 3, 4), nrow = 2)
print(matrix2
• # Multiply the matrices.
• result <- matrix1 * matrix2
• cat("Result of multiplication","n")
print(result))
• # Divide the matrices
• result <- matrix1 / matrix2
• cat("Result of division","n")
• print(result)
Matrix Access
• Create a Matrix
• x<-1:12
• Print(x)
• Mat<-matrix(x,3,4)
• Access third row of an existing matrix
• Mat[3,]
• Second column
• Mat[,2]
• Access second and third column
• Mat[,2,3]
Contour plot
• Contour plots are used to show 3-
dimensional data on a 2-dimensional surface.
The most common example of a contour plot
is a topographical map, which shows latitude
and longitude on the y and x axis, and
elevation overlaid with contours. Colours can
also be used on the map surface to further
highlight the contours
• Create a matrix, mat which is 9 rows and 9 columns with
all values are 1
• Mat<-matrix(1,9,9)
• Print(mat)
• Replace a value of 3rd row 3rd column
• Mat[3,3]<-0
• Contour(mat)
• Create a 3D perspective plot with persp(). It provides 3D
wireframe plot
• Persp(mat)
• R includes some pre defined data sets
• Volcano, which is 3D map dormant of New Zealand
• Contour(volcano)
• Heat map
• Image(volcano)

More Related Content

What's hot

Box and whisker plots
Box and whisker plotsBox and whisker plots
Box and whisker plots
Garima Gupta
 
Data Exploration in R.pptx
Data Exploration in R.pptxData Exploration in R.pptx
Data Exploration in R.pptx
Ramakrishna Reddy Bijjam
 
Number System
Number SystemNumber System
Number System
Zahid Rajeel
 
recurrence relations
 recurrence relations recurrence relations
recurrence relations
Anurag Cheela
 
Logistical Regression.pptx
Logistical Regression.pptxLogistical Regression.pptx
Logistical Regression.pptx
Ramakrishna Reddy Bijjam
 
Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplicationKumar
 
INTRODUCTION TO MATRICES, TYPES OF MATRICES,
INTRODUCTION TO MATRICES, TYPES OF MATRICES, INTRODUCTION TO MATRICES, TYPES OF MATRICES,
INTRODUCTION TO MATRICES, TYPES OF MATRICES,
AMIR HASSAN
 
Types of RELATIONS
Types of RELATIONSTypes of RELATIONS
Types of RELATIONS
Janak Singh saud
 
BCD.
BCD.BCD.
Probability distribution in R
Probability distribution in RProbability distribution in R
Probability distribution in R
Alichy Sowmya
 
Booth's Algorithm Fully Explained With Flow Chart PDF
Booth's Algorithm Fully Explained With Flow Chart PDFBooth's Algorithm Fully Explained With Flow Chart PDF
Booth's Algorithm Fully Explained With Flow Chart PDF
Parthdhwajendra Mishra
 
Chapter 4 part1-Probability Model
Chapter 4 part1-Probability ModelChapter 4 part1-Probability Model
Chapter 4 part1-Probability Model
nszakir
 
Python : Data Types
Python : Data TypesPython : Data Types
Vector in R
Vector in RVector in R
CMSC 56 | Lecture 16: Equivalence of Relations & Partial Ordering
CMSC 56 | Lecture 16: Equivalence of Relations & Partial OrderingCMSC 56 | Lecture 16: Equivalence of Relations & Partial Ordering
CMSC 56 | Lecture 16: Equivalence of Relations & Partial Ordering
allyn joy calcaben
 
Binomial distribution
Binomial distributionBinomial distribution
Binomial distribution
Hari shankar sharma
 
Contingency table
Contingency tableContingency table
Contingency table
Weam Banjar
 
Boxplot
BoxplotBoxplot
Boxplot
Kelly Jans
 
Graphics in R
Graphics in RGraphics in R
Graphics in R
Kamal Gupta Roy
 
Fundamental principle of counting -Discrete Mathematics
Fundamental principle of counting -Discrete MathematicsFundamental principle of counting -Discrete Mathematics
Fundamental principle of counting -Discrete MathematicsOmnia A. Abdullah
 

What's hot (20)

Box and whisker plots
Box and whisker plotsBox and whisker plots
Box and whisker plots
 
Data Exploration in R.pptx
Data Exploration in R.pptxData Exploration in R.pptx
Data Exploration in R.pptx
 
Number System
Number SystemNumber System
Number System
 
recurrence relations
 recurrence relations recurrence relations
recurrence relations
 
Logistical Regression.pptx
Logistical Regression.pptxLogistical Regression.pptx
Logistical Regression.pptx
 
Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplication
 
INTRODUCTION TO MATRICES, TYPES OF MATRICES,
INTRODUCTION TO MATRICES, TYPES OF MATRICES, INTRODUCTION TO MATRICES, TYPES OF MATRICES,
INTRODUCTION TO MATRICES, TYPES OF MATRICES,
 
Types of RELATIONS
Types of RELATIONSTypes of RELATIONS
Types of RELATIONS
 
BCD.
BCD.BCD.
BCD.
 
Probability distribution in R
Probability distribution in RProbability distribution in R
Probability distribution in R
 
Booth's Algorithm Fully Explained With Flow Chart PDF
Booth's Algorithm Fully Explained With Flow Chart PDFBooth's Algorithm Fully Explained With Flow Chart PDF
Booth's Algorithm Fully Explained With Flow Chart PDF
 
Chapter 4 part1-Probability Model
Chapter 4 part1-Probability ModelChapter 4 part1-Probability Model
Chapter 4 part1-Probability Model
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
 
Vector in R
Vector in RVector in R
Vector in R
 
CMSC 56 | Lecture 16: Equivalence of Relations & Partial Ordering
CMSC 56 | Lecture 16: Equivalence of Relations & Partial OrderingCMSC 56 | Lecture 16: Equivalence of Relations & Partial Ordering
CMSC 56 | Lecture 16: Equivalence of Relations & Partial Ordering
 
Binomial distribution
Binomial distributionBinomial distribution
Binomial distribution
 
Contingency table
Contingency tableContingency table
Contingency table
 
Boxplot
BoxplotBoxplot
Boxplot
 
Graphics in R
Graphics in RGraphics in R
Graphics in R
 
Fundamental principle of counting -Discrete Mathematics
Fundamental principle of counting -Discrete MathematicsFundamental principle of counting -Discrete Mathematics
Fundamental principle of counting -Discrete Mathematics
 

Similar to Vectormaths and Matrix in R.pptx

MATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesMATLAB - Arrays and Matrices
MATLAB - Arrays and Matrices
Shameer Ahmed Koya
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
Satish Gummadi
 
Matlab Overviiew 2
Matlab Overviiew 2Matlab Overviiew 2
Matlab Overviiew 2
Nazim Naeem
 
Matrix Algebra : Mathematics for Business
Matrix Algebra : Mathematics for BusinessMatrix Algebra : Mathematics for Business
Matrix Algebra : Mathematics for Business
Khan Tanjeel Ahmed
 
2.Exploration with CAS-I.Lab2.pptx
2.Exploration with CAS-I.Lab2.pptx2.Exploration with CAS-I.Lab2.pptx
2.Exploration with CAS-I.Lab2.pptx
akshatraj875
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
joellivz
 
Introduction to matlab chapter2 by Dr.Bashir m. sa'ad.pdf
Introduction to matlab chapter2 by Dr.Bashir m. sa'ad.pdfIntroduction to matlab chapter2 by Dr.Bashir m. sa'ad.pdf
Introduction to matlab chapter2 by Dr.Bashir m. sa'ad.pdf
YasirMuhammadlawan
 
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
Lakshmi Sarvani Videla
 
Variables in matlab
Variables in matlabVariables in matlab
Variables in matlabTUOS-Sam
 
Matlab ch1 (3)
Matlab ch1 (3)Matlab ch1 (3)
Matlab ch1 (3)
mohsinggg
 
working with matrices in r
working with matrices in rworking with matrices in r
working with matrices in r
Kavitha Chandramohan
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arrays
Ameen San
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
Murshida ck
 
Matlab-1.pptx
Matlab-1.pptxMatlab-1.pptx
Matlab-1.pptx
aboma2hawi
 
Learning R
Learning RLearning R
Learning R
Kamal Gupta Roy
 
Matrix algebra in_r
Matrix algebra in_rMatrix algebra in_r
Matrix algebra in_r
Razzaqe
 
2. Array in Data Structure
2. Array in Data Structure2. Array in Data Structure
2. Array in Data Structure
Mandeep Singh
 
Basic MATLAB-Presentation.pptx
Basic MATLAB-Presentation.pptxBasic MATLAB-Presentation.pptx
Basic MATLAB-Presentation.pptx
PremanandS3
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
Mohd Esa
 

Similar to Vectormaths and Matrix in R.pptx (20)

MATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesMATLAB - Arrays and Matrices
MATLAB - Arrays and Matrices
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Matlab Overviiew 2
Matlab Overviiew 2Matlab Overviiew 2
Matlab Overviiew 2
 
Matrix Algebra : Mathematics for Business
Matrix Algebra : Mathematics for BusinessMatrix Algebra : Mathematics for Business
Matrix Algebra : Mathematics for Business
 
2.Exploration with CAS-I.Lab2.pptx
2.Exploration with CAS-I.Lab2.pptx2.Exploration with CAS-I.Lab2.pptx
2.Exploration with CAS-I.Lab2.pptx
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
 
Introduction to matlab chapter2 by Dr.Bashir m. sa'ad.pdf
Introduction to matlab chapter2 by Dr.Bashir m. sa'ad.pdfIntroduction to matlab chapter2 by Dr.Bashir m. sa'ad.pdf
Introduction to matlab chapter2 by Dr.Bashir m. sa'ad.pdf
 
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
 
Variables in matlab
Variables in matlabVariables in matlab
Variables in matlab
 
Matlab ch1 (3)
Matlab ch1 (3)Matlab ch1 (3)
Matlab ch1 (3)
 
working with matrices in r
working with matrices in rworking with matrices in r
working with matrices in r
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arrays
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
 
Matlab-1.pptx
Matlab-1.pptxMatlab-1.pptx
Matlab-1.pptx
 
Learning R
Learning RLearning R
Learning R
 
Matrix algebra in_r
Matrix algebra in_rMatrix algebra in_r
Matrix algebra in_r
 
2. Array in Data Structure
2. Array in Data Structure2. Array in Data Structure
2. Array in Data Structure
 
Basic MATLAB-Presentation.pptx
Basic MATLAB-Presentation.pptxBasic MATLAB-Presentation.pptx
Basic MATLAB-Presentation.pptx
 
bobok
bobokbobok
bobok
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
 

More from Ramakrishna Reddy Bijjam

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
Ramakrishna Reddy Bijjam
 
Arrays to arrays and pointers with arrays.pptx
Arrays to arrays and pointers with arrays.pptxArrays to arrays and pointers with arrays.pptx
Arrays to arrays and pointers with arrays.pptx
Ramakrishna Reddy Bijjam
 
Auxiliary, Cache and Virtual memory.pptx
Auxiliary, Cache and Virtual memory.pptxAuxiliary, Cache and Virtual memory.pptx
Auxiliary, Cache and Virtual memory.pptx
Ramakrishna Reddy Bijjam
 
Python With MongoDB in advanced Python.pptx
Python With MongoDB in advanced Python.pptxPython With MongoDB in advanced Python.pptx
Python With MongoDB in advanced Python.pptx
Ramakrishna Reddy Bijjam
 
Pointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptxPointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptx
Ramakrishna Reddy Bijjam
 
Certinity Factor and Dempster-shafer theory .pptx
Certinity Factor and Dempster-shafer theory .pptxCertinity Factor and Dempster-shafer theory .pptx
Certinity Factor and Dempster-shafer theory .pptx
Ramakrishna Reddy Bijjam
 
Auxiliary Memory in computer Architecture.pptx
Auxiliary Memory in computer Architecture.pptxAuxiliary Memory in computer Architecture.pptx
Auxiliary Memory in computer Architecture.pptx
Ramakrishna Reddy Bijjam
 
Random Forest Decision Tree.pptx
Random Forest Decision Tree.pptxRandom Forest Decision Tree.pptx
Random Forest Decision Tree.pptx
Ramakrishna Reddy Bijjam
 
K Means Clustering in ML.pptx
K Means Clustering in ML.pptxK Means Clustering in ML.pptx
K Means Clustering in ML.pptx
Ramakrishna Reddy Bijjam
 
Pandas.pptx
Pandas.pptxPandas.pptx
Python With MongoDB.pptx
Python With MongoDB.pptxPython With MongoDB.pptx
Python With MongoDB.pptx
Ramakrishna Reddy Bijjam
 
Python with MySql.pptx
Python with MySql.pptxPython with MySql.pptx
Python with MySql.pptx
Ramakrishna Reddy Bijjam
 
PYTHON PROGRAMMING NOTES RKREDDY.pdf
PYTHON PROGRAMMING NOTES RKREDDY.pdfPYTHON PROGRAMMING NOTES RKREDDY.pdf
PYTHON PROGRAMMING NOTES RKREDDY.pdf
Ramakrishna Reddy Bijjam
 
BInary file Operations.pptx
BInary file Operations.pptxBInary file Operations.pptx
BInary file Operations.pptx
Ramakrishna Reddy Bijjam
 
Data Science in Python.pptx
Data Science in Python.pptxData Science in Python.pptx
Data Science in Python.pptx
Ramakrishna Reddy Bijjam
 
CSV JSON and XML files in Python.pptx
CSV JSON and XML files in Python.pptxCSV JSON and XML files in Python.pptx
CSV JSON and XML files in Python.pptx
Ramakrishna Reddy Bijjam
 
HTML files in python.pptx
HTML files in python.pptxHTML files in python.pptx
HTML files in python.pptx
Ramakrishna Reddy Bijjam
 
Regular Expressions in Python.pptx
Regular Expressions in Python.pptxRegular Expressions in Python.pptx
Regular Expressions in Python.pptx
Ramakrishna Reddy Bijjam
 
datareprersentation 1.pptx
datareprersentation 1.pptxdatareprersentation 1.pptx
datareprersentation 1.pptx
Ramakrishna Reddy Bijjam
 
Apriori.pptx
Apriori.pptxApriori.pptx

More from Ramakrishna Reddy Bijjam (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Arrays to arrays and pointers with arrays.pptx
Arrays to arrays and pointers with arrays.pptxArrays to arrays and pointers with arrays.pptx
Arrays to arrays and pointers with arrays.pptx
 
Auxiliary, Cache and Virtual memory.pptx
Auxiliary, Cache and Virtual memory.pptxAuxiliary, Cache and Virtual memory.pptx
Auxiliary, Cache and Virtual memory.pptx
 
Python With MongoDB in advanced Python.pptx
Python With MongoDB in advanced Python.pptxPython With MongoDB in advanced Python.pptx
Python With MongoDB in advanced Python.pptx
 
Pointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptxPointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptx
 
Certinity Factor and Dempster-shafer theory .pptx
Certinity Factor and Dempster-shafer theory .pptxCertinity Factor and Dempster-shafer theory .pptx
Certinity Factor and Dempster-shafer theory .pptx
 
Auxiliary Memory in computer Architecture.pptx
Auxiliary Memory in computer Architecture.pptxAuxiliary Memory in computer Architecture.pptx
Auxiliary Memory in computer Architecture.pptx
 
Random Forest Decision Tree.pptx
Random Forest Decision Tree.pptxRandom Forest Decision Tree.pptx
Random Forest Decision Tree.pptx
 
K Means Clustering in ML.pptx
K Means Clustering in ML.pptxK Means Clustering in ML.pptx
K Means Clustering in ML.pptx
 
Pandas.pptx
Pandas.pptxPandas.pptx
Pandas.pptx
 
Python With MongoDB.pptx
Python With MongoDB.pptxPython With MongoDB.pptx
Python With MongoDB.pptx
 
Python with MySql.pptx
Python with MySql.pptxPython with MySql.pptx
Python with MySql.pptx
 
PYTHON PROGRAMMING NOTES RKREDDY.pdf
PYTHON PROGRAMMING NOTES RKREDDY.pdfPYTHON PROGRAMMING NOTES RKREDDY.pdf
PYTHON PROGRAMMING NOTES RKREDDY.pdf
 
BInary file Operations.pptx
BInary file Operations.pptxBInary file Operations.pptx
BInary file Operations.pptx
 
Data Science in Python.pptx
Data Science in Python.pptxData Science in Python.pptx
Data Science in Python.pptx
 
CSV JSON and XML files in Python.pptx
CSV JSON and XML files in Python.pptxCSV JSON and XML files in Python.pptx
CSV JSON and XML files in Python.pptx
 
HTML files in python.pptx
HTML files in python.pptxHTML files in python.pptx
HTML files in python.pptx
 
Regular Expressions in Python.pptx
Regular Expressions in Python.pptxRegular Expressions in Python.pptx
Regular Expressions in Python.pptx
 
datareprersentation 1.pptx
datareprersentation 1.pptxdatareprersentation 1.pptx
datareprersentation 1.pptx
 
Apriori.pptx
Apriori.pptxApriori.pptx
Apriori.pptx
 

Recently uploaded

一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
yhkoc
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
axoqas
 
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Subhajit Sahu
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
nscud
 
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
axoqas
 
Tabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflowsTabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflows
alex933524
 
Jpolillo Amazon PPC - Bid Optimization Sample
Jpolillo Amazon PPC - Bid Optimization SampleJpolillo Amazon PPC - Bid Optimization Sample
Jpolillo Amazon PPC - Bid Optimization Sample
James Polillo
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .
NABLAS株式会社
 
Q1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year ReboundQ1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year Rebound
Oppotus
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
ewymefz
 
Business update Q1 2024 Lar España Real Estate SOCIMI
Business update Q1 2024 Lar España Real Estate SOCIMIBusiness update Q1 2024 Lar España Real Estate SOCIMI
Business update Q1 2024 Lar España Real Estate SOCIMI
AlejandraGmez176757
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
NABLAS株式会社
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
AbhimanyuSinha9
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
TravisMalana
 
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
Tiktokethiodaily
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
enxupq
 
tapal brand analysis PPT slide for comptetive data
tapal brand analysis PPT slide for comptetive datatapal brand analysis PPT slide for comptetive data
tapal brand analysis PPT slide for comptetive data
theahmadsaood
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
John Andrews
 

Recently uploaded (20)

一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
 
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
 
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
 
Tabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflowsTabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflows
 
Jpolillo Amazon PPC - Bid Optimization Sample
Jpolillo Amazon PPC - Bid Optimization SampleJpolillo Amazon PPC - Bid Optimization Sample
Jpolillo Amazon PPC - Bid Optimization Sample
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .
 
Q1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year ReboundQ1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year Rebound
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
 
Business update Q1 2024 Lar España Real Estate SOCIMI
Business update Q1 2024 Lar España Real Estate SOCIMIBusiness update Q1 2024 Lar España Real Estate SOCIMI
Business update Q1 2024 Lar España Real Estate SOCIMI
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
 
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
1.Seydhcuxhxyxhccuuxuxyxyxmisolids 2019.pptx
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
 
tapal brand analysis PPT slide for comptetive data
tapal brand analysis PPT slide for comptetive datatapal brand analysis PPT slide for comptetive data
tapal brand analysis PPT slide for comptetive data
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
 

Vectormaths and Matrix in R.pptx

  • 1. Vector Maths Arithmetic operations of vectors are performed member-by-member, i.e., member wise. For example, suppose we have two vectors a and b. > a = c(1, 3, 5, 7) > b = c(1, 2, 4, 8) Then, if we multiply a by 5, we would get a vector with each of its members multiplied by 5. > 5 * a [1] 5 15 25 35 And if we add a and b together, the sum would be a vector whose members are the sum of the corresponding members from a and b. > a + b [1] 2 5 9 15 Similarly for subtraction, multiplication and division, we get new vectors via memberwise operations. > a - b [1] 0 1 1 -1 > a * b [1] 1 6 20 56 > a / b [1] 1.000 1.500 1.250 0.875
  • 2. Recycling Rule • If two vectors are of unequal length, the shorter one will be recycled in order to match the longer vector. For example, the following vectors u and v have different lengths, and their sum is computed by recycling values of the shorter vector u. • > u = c(10, 20, 30) > v = c(1, 2, 3, 4, 5, 6, 7, 8, 9) > u + v [1] 11 22 33 14 25 36 17 28 39
  • 3. Vector Index • Vector Index • We retrieve values in a vector by declaring an index inside a single square bracket "[]" operator. • For example, the following shows how to retrieve a vector member. Since the vector index is 1-based, we use the index position 3 for retrieving the third member. • > s = c("aa", "bb", "cc", "dd", "ee") > s[3] [1] "cc"
  • 4. Negative Index • If the index is negative, it would strip the member whose position has the same absolute value as the negative index. • For example, the following creates a vector slice with the third member removed. • > s[-3] [1] "aa" "bb" "dd" "ee" • Out-of-Range Index • If an index is out-of-range, a missing value will be reported via the symbol NA. • > s[10] [1] NA
  • 5. Matrix • A matrix is a collection of data elements arranged in a two-dimensional rectangular layout. The following is an example of a matrix with 2 rows and 3 columns. • We reproduce a memory representation of the matrix in R with the matrix function. The data elements must be of the same basic type.
  • 6. • > A = matrix( + c(2, 4, 3, 1, 5, 7), # the data elements + nrow=2, # number of rows + ncol=3, # number of columns + byrow = T • A # print the matrix [,1] [,2] [,3] [1,] 2 4 3 [2,] 1 5 7RUE) # fill matrix by rows
  • 7. • An element at the mth row, nth column of A can be accessed by the expression A[m, n]. • > A[2, 3] # element at 2nd row, 3rd column [1] 7 • The entire mth row A can be extracted as A[m, ]. • > A[2, ] # the 2nd row [1] 1 5 7 • Similarly, the entire nth column A can be extracted as A[ ,n]. • > A[ ,3] # the 3rd column [1] 3 7 • We can also extract more than one rows or columns at a time. • > A[ ,c(1,3)] # the 1st and 3rd columns [,1] [,2] [1,] 2 3 [2,] 1 7
  • 8. Matrix Addition & Subtraction • # Create two 2x3 matrices. • matrix1 <- matrix(c(3, 9, -1, 4, 2, 6), nrow = 2) print(matrix1) • matrix2 <- matrix(c(5, 2, 0, 9, 3, 4), nrow = 2) print(matrix2) • # Add the matrices. • result <- matrix1 + matrix2 • cat("Result of addition","n") • print(result) • # Subtract the matrices • result <- matrix1 - matrix2 • cat("Result of subtraction","n") print(result)
  • 9. Matrix Multiplication & Division • # Create two 2x3 matrices. • matrix1 <- matrix(c(3, 9, -1, 4, 2, 6), nrow = 2) print(matrix1) • matrix2 <- matrix(c(5, 2, 0, 9, 3, 4), nrow = 2) print(matrix2 • # Multiply the matrices. • result <- matrix1 * matrix2 • cat("Result of multiplication","n") print(result))
  • 10. • # Divide the matrices • result <- matrix1 / matrix2 • cat("Result of division","n") • print(result)
  • 11. Matrix Access • Create a Matrix • x<-1:12 • Print(x) • Mat<-matrix(x,3,4) • Access third row of an existing matrix • Mat[3,] • Second column • Mat[,2] • Access second and third column • Mat[,2,3]
  • 12. Contour plot • Contour plots are used to show 3- dimensional data on a 2-dimensional surface. The most common example of a contour plot is a topographical map, which shows latitude and longitude on the y and x axis, and elevation overlaid with contours. Colours can also be used on the map surface to further highlight the contours
  • 13. • Create a matrix, mat which is 9 rows and 9 columns with all values are 1 • Mat<-matrix(1,9,9) • Print(mat) • Replace a value of 3rd row 3rd column • Mat[3,3]<-0 • Contour(mat) • Create a 3D perspective plot with persp(). It provides 3D wireframe plot • Persp(mat) • R includes some pre defined data sets • Volcano, which is 3D map dormant of New Zealand • Contour(volcano) • Heat map • Image(volcano)