Bsta 3152 Practical 2
Bsta 3152 Practical 2
INSTRUCTIONS
1. AnswerALL questions
2. Write clear well commented codes.
3. Knit a html file or word converted to pdf for your task.
4 Upload your work on the Emasomo link before the due date provided.
NB:Any task sent after the time has lapsed will attract a score of 0(ZERO).
2. R chunk 1: Consider the Bank.csv data file provided for you. Use the data to perform
the following tasks.
(a) Input the data into R and form a 3 × 4 matrix named Matrix1.
(b) Output the first row of Matrix1.
(c) Output the element in the 2nd row and 3rd column.
(d) Find the inverse of Matrix1.
4. R chunk 3: Using the data below, perform the following task writing well-commented
codes:
Table 1: Student Performance Data
Gender Race Lunch Prep Course Statistics Score Reading Score Writing Score
Female Group B Standard None 72 72 74
Female Group C Standard Completed 69 90 88
Female Group B Standard None 90 95 93
Male Group A Free None 47 57 44
Male Group C Standard None 76 78 75
Female Group B Standard None 71 83 78
(a) Input the data into R environment and outputs the table.
(b) Output the first 5 rows of the data.
(c) Filter observations for female students.
(d) Sort the observations using the Statistics Scores in ascending order and Reading Scores
in descending order.
(e) Create a new column titled âTotal Scoreâ that calculates the total score for each student
in the three subjects.
(f) Performs correlation between Statistics score and Writing Score and plots a Scatter
plot of the two variables.
(g) Plot a histogram of the Statistic Score
5p + 2q − r = 5
p − 4q + 5r = −1
2p + q + 3r = 10
6. R chunk 5: Write a function in R that accepts a vector of numbers and returns product,
mean and variance of the vector.
2
7. R chunk 6: Consider the following function f (x) = x cos(x)+2xsin(x)
x4 +cos(x)
. Write well commented
R codes to find the integral of the function where 2 ≤ x ≤ 4.
8. R chunk 7: Use R to find the second derivative of f (x) = x4 − 3x3 + 2x2 with respect to
x. Write a well commented R code to compute and display the second derivative.