0% found this document useful (0 votes)
40 views3 pages

Exercise 1 MTH3409

This document contains 14 computational statistics exercises involving R code. The exercises cover topics like data manipulation, matrix operations, logical operators, and matrix inverse calculations. The goal is to write R code to perform the specified tasks and calculations.

Uploaded by

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

Exercise 1 MTH3409

This document contains 14 computational statistics exercises involving R code. The exercises cover topics like data manipulation, matrix operations, logical operators, and matrix inverse calculations. The goal is to write R code to perform the specified tasks and calculations.

Uploaded by

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

EXERCISE 1 MTH3409 – COMPUTATIONAL STATISTICS SEM 1 2022/2023

1. Write some R code that will produce the output:


a. “Mahathir Mohamad” if name1<- “Mahathir” and name2 <- “Mohamad”.
b.
Names Group Code
Dr. Muhammad Aslam Mohd Safari Group 1 MTH3409-Lecture
Dr. Muhammad Aslam Mohd Safari Group 1 MTH3409-Lab
Dr. Muhammad Aslam Mohd Safari Group 2 MTH3409-Lab

2. Create the following variables and check they are correct.


Variable name Value Answer
k1 5 × 4 + 6 ÷ 4 − 1.2 20.3
k2 33 − 1 26
k3 𝑒𝑒 3×6−15 − 2 18.08554
k4 564 mod 17 3
k5 cos (𝜋𝜋/6) 0.8660254
k6 √81 9
k7 log10 (67) 1.826075
k8 log 𝑒𝑒 (−1) NaN
k9 x1 + x2 − x3 ÷ x4 40.27149

3. If Z = NA, 3, 145, NA, 33, 176, NA, 41, write some R code that will remove all occurrences
of NA in Z.

4. The tasks are as follows:


a. Create a vector with 12 integers. Convert the vector to a 3 × 4 matrix and the matrix
name is best. Please change the column names to w, x, y, z and row names to a, b, c.
b. Please obtain the transpose matrix of best.
c. Compute the matrix best multiplies transpose.

5. Consider the following data:


Name Sales Price
NA 15 33
Zul 45 52
Nora 21 25
Peter 52 44
NA 60 20
Write some R code that will return a data frame which removes all rows with NA values
in Name column.
6. Create a vector Z containing the integers from -10 to 10 and a vector W of 0 1 2 3.

7. Use the R function rep() and seq() to create the following sequences:
6 6 6 6 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10
45674567456745674567
12342345345645675678

8. Create the following vector:


M1=1,2,3,4,5,6,7,8,9,10
M2=3,6,9,12,15,18,21,24,27,30
Then, calculate the sum of the 4th element of M1 and 9th element of M2.

9. Based on M1 and M2 in Ques. (8), use the logical operators and the which() function to
determine
a. Which elements of M2 are greater than 16.
b. Which elements of M2 are between than 9 and 24 inclusive.
c. Which elements of M1 are greater than 4 or divisible by 3.

10. Find log 𝑒𝑒 0.53. Next, compute the exponential transform of your answer.

11. Create a vector, Z = c(3,0.5,6,6,0.5,6,3,0.5,6).


a. In this vector, replace any values other than 0.5 with 5.
b. Convert the original vector Z to a vector of only 1s, using a vector of length 3.

12. Write a R code for the following matrix.


a. Construct and store a 4 × 2 matrix that’s filled row-wise with the values 3.3, 4.1, 8.2,
8.2, 3.2, 1.9, 1.6, and 6.7, in that order.
b. Confirm the dimensions of the matrix from (a) are 3 × 2 if you remove any one row.
c. Overwrite the first column of the matrix from (a) with that same column sorted from
smallest to largest.

13. Calculate the following


2 1 2 10 20
��2 4� − �30 40��
7
7 6 50 60
14. For
2 0 0 0
0 3 0 0
𝐴𝐴 = � �
0 0 5 0
0 0 0 −1
Confirm that 𝐴𝐴−1 ∙ 𝐴𝐴 − 𝐼𝐼 provides a 4 × 4 matrix of zeros. (I is an identity matrix)

You might also like