Problem 1

Do the following calculations in R

  1. (54)^(45)-56
  2. 23-1*(8-12)
  3. 56/8*(3+4)
  4. 45-5*8+(8+9)
a <- (5*4)^(4*5)-56

b <- 23-1*(8-12)

c <- 56/8*(3+4)


d <- 45-5*8+(8+9)
  
cat("a =",a,"\n") 
## a = 1.048576e+26
cat("b =",b,"\n")
## b = 27
cat("c =",c,"\n")
## c = 49
cat("d =",d,"\n")
## d = 22

Problem 2

Create the following vectors a, b, and c a) 2,5,6,7 b) 1,0,9,8 c) 6,5,8,3

Row bind the vectors to form a 3X4 matrix. Change the column names to (Mon, Tue, Wed, Thu). Change the row names to (Present, Absent, On leave). Calculate the row sums and the column sums.

v1 <- c(2, 5, 6, 7)
v2 <- c(1, 0, 9, 8)
v3 <- c(6, 5, 8, 3)

mat <- rbind(v1, v2, v3)
colnames(mat) <- c("Mon", "Tue", "Wed", "Thu" )
rownames(mat) <- c("Present", "Absent", "On leave")
rowsums <- rowSums(mat)
colsums <- colSums(mat)
cat("Matrix:\n")
## Matrix:
print(mat)
##          Mon Tue Wed Thu
## Present    2   5   6   7
## Absent     1   0   9   8
## On leave   6   5   8   3
cat("\nRow Sums:\n\n")
## 
## Row Sums:
print(rowsums)
##  Present   Absent On leave 
##       20       18       22
cat("\nColumn Sums:\n\n")
## 
## Column Sums:
print(colsums)
## Mon Tue Wed Thu 
##   9  10  23  18