Problem 1a
print(5*4)^(4*5)-56
## [1] 20
## [1] 1.048576e+26
Problem 1b
print (23-1*(8-12))
## [1] 27
Problem 1c
print(56/8*(3+4))
## [1] 49
Problem 1d
print(45-5*8+(8+9))
## [1] 22
##Creating Vectors
Problem 2a
print (x <-c(2,5,6,7))
## [1] 2 5 6 7
Problem 2b
print (y <-c(1,0,9,8))
## [1] 1 0 9 8
Problem 2c
print (z <-c(6,5,8,3))
## [1] 6 5 8 3
##Combining Vectors to form a matrix
d <-c(x,y,z)
d
## [1] 2 5 6 7 1 0 9 8 6 5 8 3
mat<- matrix(d,
byrow=TRUE,
nrow=3)
print(mat)
## [,1] [,2] [,3] [,4]
## [1,] 2 5 6 7
## [2,] 1 0 9 8
## [3,] 6 5 8 3
##Naming Columns and rows
colnames(mat)<-c('Mon', 'Tue', 'Wed', 'Thu')
mat
## Mon Tue Wed Thu
## [1,] 2 5 6 7
## [2,] 1 0 9 8
## [3,] 6 5 8 3
rownames(mat)<-c('Present', 'Absent', 'On leave')
mat
## Mon Tue Wed Thu
## Present 2 5 6 7
## Absent 1 0 9 8
## On leave 6 5 8 3
##Calculating Rowsums and Columnsums
row<-rowSums(mat)
row
## Present Absent On leave
## 20 18 22
col<-colSums(mat)
col
## Mon Tue Wed Thu
## 9 10 23 18
##Row bind and Column bind
mat<-matrix(d,
byrow=TRUE,
nrow=3)
mat
## [,1] [,2] [,3] [,4]
## [1,] 2 5 6 7
## [2,] 1 0 9 8
## [3,] 6 5 8 3
mat1<-cbind(mat,row)
mat1
## row
## Present 2 5 6 7 20
## Absent 1 0 9 8 18
## On leave 6 5 8 3 22
mat
## [,1] [,2] [,3] [,4]
## [1,] 2 5 6 7
## [2,] 1 0 9 8
## [3,] 6 5 8 3
mat2<-rbind(mat,col)
mat2
## Mon Tue Wed Thu
## 2 5 6 7
## 1 0 9 8
## 6 5 8 3
## col 9 10 23 18