Total Points: 30

To begin, please follow the links in the course syllabus to download R, RStudio, and R Markdown. You should edit this .Rmd using RStudio, then click Knit in the menu bar of the source window (above the text of this .Rmd). Remember, you must submit your knitted PDF file through Canvas in order to receive full credit!

Part 1. Basic R Code (2pts per question)

  1. Use R to compute 1+2*(3+4).
# Your code here
  1. Use R to compute the logarithm of 18+3*2 under the natural base and base 2.
# Your code here (two lines)
  1. Suppose that a student had his original score as 70. However, he submitted his homework 6 hours and 20 minutes late for the deadline. Use R to calculate his final score.
# Your code here
  1. Use R build-in function to compute 6! (i.e., \(6\times 5\times 4 \times 3\times 2\times 1\)).
# Your code here
  1. Are the outputs of round(6.6) and as.integer(6.6) the same?
# Your code here (Hint: the output should be TRUE/FALSE)
  1. Use R function to check whether the data type of 3.2 is numeric.
# Your code here (output should be TRUE/FALSE)
  1. What are the data type and the length of “James”?
# Your code here (Two lines)
  1. What is the result of 0/0? Is it equal to NA?
# Your code here (Two lines)

Part 2: Explore build-in R functions (4pts per question)

Look at the documentation of the following R functions seq, factorial, and choose. Use at least two ways in R to achieve the followings.

  1. Generate the sequence: -0.8, -0.4, 0, 0.4, 0.8, 1.2, 1.6.
# Your code here (At least two lines)
  1. Compute \(7\choose 4\) (this was produced by command $7 \choose 4$).
# Your code here (At least two lines)

Part 3: Computing Summary Statistics of A Vector Variable (1pt per question)

Run the following command to create an object.

## Run it before proceeding to the questions
x <- c(1, 8, -3.2, 5, -1, 15.3)

Use R to do the followings:

  1. Compute the length of the object x.
# Your code here
  1. Compute the sum of x.
# Your code here
  1. Compute the cumulative sum of x.
# Your code here (Hint: the output has the same length as x.)
  1. Output the index of elements in x that is >1.5. Hint: look at the documentation of which().
# Your code here
  1. Find the minimum value of x.
# Your code here
  1. Order the values of the vector x from low to high.
# Your code here