Description
1. Consider the built‐in data frame pressure. (a) Plot pressure against temperature, and use the following command to pass a curve through these data: curve((0.168 + 0.007*x)ˆ(20/3), from = 0, to = 400, add = TRUE) (b) Now, apply the power transformation y3/20 to the pressure data values. Plot these transformed values against temperature. Is a linear or nonlinear relationship evident now? Use the abline() function to pass a straight line through the points. (You need an intercept and slope for this – see the part (a) of this question to obtain appropriate values.) (c) Add a suitable title to the graph. (d) Re‐do the above plots, but use the mfrow() function to display them in a 1 × 2 layout on the graphics page. Suppress the surrounding box and arrange the numeric axis labels to be horizontal. A sample output is given below. (see help(par)) 2. Write a function named alt_matrix() which accept a positive integer n and return a square matrix with alternating 0 and 1 as shown below. > alt_matrix(7) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 0 1 0 1 0 1 0 [2,] 1 0 1 0 1 0 1 [3,] 0 1 0 1 0 1 0 [4,] 1 0 1 0 1 0 1 [5,] 0 1 0 1 0 1 0 [6,] 1 0 1 0 1 0 1 [7,] 0 1 0 1 0 1 0 3. Use R to draw the following graph. Note: the four colours are “red”, “orange”, “green”, and “blue”. 4. A twin prime is a pair of primes (x, y), such that y = x + 2. Construct a list of all twin primes less than 1000. You should submit a file asg2.r via Blackboard, which contains all the R codes you use to finish this assignment. The codes should be commented as clearly as possible. Written work (if any) should also be submitted to the assignment drop‐box.


