0% found this document useful (0 votes)
7 views6 pages

Matrices

Uploaded by

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

Matrices

Uploaded by

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

Jatin Bhardwaj

24HMT3144

[1]

seq(from=1,to=10,by=0.5)

[1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5

[19] 10.0

[2]

> vector=c(seq(from=2,to=20,by=2))

> print(vector)

[1] 2 4 6 8 10 12 14 16 18 20

2(1)

> vector[c(5)]

[1] 10

2(2)

> vector[c(-5)]

[1] 2 4 6 8 12 14 16 18 20

2(3)

> vector[vector>=12]

[1] 12 14 16 18 20

> A=matrix(c(4,2,1,7,0,6,5,2,9),byrow=TRUE,nrow=3)

> print(A)

[,1] [,2] [,3]

[1,] 4 2 1

[2,] 7 0 6

[3,] 5 2 9
#3(1)

> A[2,3]

[1] 6

3(2)

> A[,3]

[1] 1 6 9

3(3)

> A[,1]

[1] 4 7 5

#3(VI)

> A[A==4]<-24

> print(A)

[,1] [,2] [,3]

[1,] 24 2 1

[2,] 7 0 6

[3,] 5 2 9

> #3(VII)

> rbind(A,c(12,14,16))

[,1] [,2] [,3]

[1,] 24 2 1

[2,] 7 0 6

[3,] 5 2 9

[4,] 12 14 16

> cbind(A,c(3,5,7))

[,1] [,2] [,3] [,4]

[1,] 24 2 1 3
[2,] 7 0 6 5

[3,] 5 2 9 7 3(8)

row_name=c("row1","row2","row3")

> col_name=c("col1","col2","col3")

>
A=matrix(c(4,2,1,7,0,6,5,2,9),byrow=TRUE,nrow=3,dimnames=list(row_name,col_name
))

> print(A) col1

col2 col3

row1 4 2 1

row2 7 0 6

row3 5 2 9

3(9)

A=A[-c(3),] >

print(A) col1

col2 col3

row1 4 2 1

row2 7 0 6

3(10)

>
A=matrix(c(4,2,1,7,0,6,5,2,9),byrow=TRUE,nrow=3,dimnames=list(row_name,col_name
))

> print(A) col1

col2 col3

row1 4 2 1

row2 7 0 6
row3 5 2 9

17%in%A

[1] FALSE

3(11)

A=matrix(c(4,2,1,7,0,6,5,2,9),byrow=TRUE,nrow=3,dimnames=list(row_name,col_name
))

> print(A) col1

col2 col3

row1 4 2 1

row2 7 0 6

row3 5 2 9

3(13)

> length(A)

[1] 9

3(12)

> dim(A)

[1] 3 3

3(13)

A1=matrix(c(1,2,3,4),nrow=2,byrow=TRUE)

A2=matrix(c(5,6,7,8),nrow=2,byrow=TRUE)

Mat_combine=rbind(A1,A2)

Print(mat_combine)

[,1] [,2]

[1,] 1 2
[2,] 3 4

[3,] 5 6

[4,] 7 8

A1=matrix(c(1,2,3,4),nrow=2,byrow=TRUE)

A2=matrix(c(5,6,7,8),nrow=2,byrow=TRUE)

Mat_combine=cbind(A1,A2)

Print(mat_combine)

[,1] [,2] [,3] [,4]

[1,] 1 2 5 6

[2,] 3 4 7 8

3(14)

A3=matrix(5,3,3)

Print(A3)

[,1] [,2] [,3]

[1,] 5 5 5

[2,] 5 5 5

[3,] 5 5 5

3(15)

A4=diag(c(1,2,3),3,3)

Print(A4)

[,1] [,2] [,3]


[1,] 1 0 0

[2,] 0 2 0

[3,] 0 0 3

A5=diag(c(1,1,1,1),4,4)

> print(A5)

[,1] [,2] [,3] [,4]

[1,] 1 0 0 0

[2,] 0 1 0 0

[3,] 0 0 1 0

[4,] 0 0 0 1

You might also like