Question
PLEASE LABEL EACH NUMBER and its ANSWER Write an R script that contains statements to accomplish the following numbered items. Use R comments (a line
PLEASE LABEL EACH NUMBER and its ANSWER
Write an R script that contains statements to accomplish the following numbered items. Use R comments (a line starting with the # symbol) to clearly indicate for which numbered item the statements are intended. A template file titled COS-206_Written_Assignment_Template.R can be found in the Course Documents folder.
- Create a factor vector called status, which has 4 levels, namely freshman, sophomore, junior, and senior.
- words=c(78.1,23.4,35.6,97.6).
- Write R code(s) to convert the vector words to a numeric vector called numbers, which contains the corresponding number for each item in words. For instance, the first item in numbersis 78.1.
- data=c(-1.7382021,1.0636014,1.9335294,0.4239470,-1.5176473,1.7202728,1.0427466,1.9482044,-0.7755854,0.4915089)
- What is the min, max, and mean of the vector data? (report at least 4 digits after decimal point).
- Write R code(s) to create the following sequence. 3.2,3.4,3.6,3.8,4.0,4.2,4.4,4.6,4.8
- Write R code(s) to create a numeric vector with 3 items 1, 2, and 3. The first item 1 has name one, the second item has name two, the third item has name three.
- Write R code(s) to create the following matrix called counts.
Mon | Tue | Wed | |
Adam | 1 | 2 | 3 |
Bell | 4 | 5 | 6 |
Coach | 7 | 8 | 9 |
- Using the matrix counts created in question 7, write R code(s) to:
- retrieve the count for Bell on Wed.
- retrieve the counts for Coach
- retrieve the counts on Mon
- Write codes to add another row of data to the matrix counts created in question 7. The final matrix should looks like the one below.
Mon | Tue | Wed | |
Adam | 1 | 2 | 3 |
Bell | 4 | 5 | 6 |
Coach | 7 | 8 | 9 |
Dell | 10 | 11 | 12 |
- Write codes to add another column of data to the matrix counts created in question 7. The final matrix looks like below.
Mon | Tue | Wed | Thur | |
Adam | 1 | 2 | 3 | 10 |
Bell | 4 | 5 | 6 | 11 |
Coach | 7 | 8 | 9 | 12 |
- Write R code(s) to:
a. Create a matrix called amatrix that looks like the one below.
[,1] | [,2] | [,3] | |
[1,] | 1 | 4 | 7 |
[2,] | 2 | 5 | 8 |
[3,] | 3 | 6 | 9 |
b. Create a matrix called bmatrix that looks like the one below.
[,1] | [,2] | [,3] | |
[1,] | 1 | 2 | 3 |
[2,] | 4 | 5 | 6 |
[3,] | 7 | 8 | 9 |
c. Transpose amatrix.
d. Calculate the inner multiplication of amatrix and bmatrix.
e. Find the inverse of the element-wise products of amatrix and bmatrix.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started