Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an R script that contains statements to accomplish the following numbered

ID: 3773698 • Letter: W

Question

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.

1. Create a factor vector called status, which has 4 levels, namely freshman, sophomore, junior, and senior.

2.  words=c(“78.1”,”23.4”,”35.6”,”97.6”).
       a. Write R code(s) to convert the vector words to a numeric vector callednumbers, which contains the corresponding number for each item in words. For instance, the first item in numbers is 78.1.

3. data=c(-1.7382021,1.0636014,1.9335294,0.4239470,-1.5176473,1.7202728,1.0427466,1.9482044,-0.7755854,0.4915089)
       a. What is the min, max, and mean of the vector data? (report at least 4 digits after decimal point).

4. 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

5. 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”.

6. 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

7. Using the matrix counts created in question 7, write R code(s) to
       a. retrieve the count for Bell on Wed.
       b. retrieve the counts for Coach
       c. retrieve the counts on Mon

8. 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

9. 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

10. 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.

Mon

Tue

Wed

Adam

1

2

3

Bell

4

5

6

Coach

7

8

9

Explanation / Answer

status <- factor (c("freshman", "sophomore", "junior", "senior"))
words=c(“78.1”,”23.4”,”35.6”,”97.6”)
data=c(-1.7382021,1.0636014,1.9335294,0.4239470,-1.5176473,1.7202728,1.0427466,1.9482044,-0.7755854,0.4915089)
seq(3.2, 4.8, by = 0.2)
as.numeric(c(1, 2, 3))
counts <- matrix(c(1,2,3, 4,5,6, 7,8,9), nrow = 3, ncol = 3, byrow = TRUE,
               dimnames = list(c("Adam", "Bell", "Coach"),
                               c("Mon", "Tue", "Wed")))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote