Practice R
January 15, 2021
You have 15 questions in this quiz. You may use RStudio to help you answer the questions.
Quiz Summary
0 of 15 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
Results
Results
0 of 15 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Categories
 R code 0%
 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 Current
 Review
 Answered
 Correct
 Incorrect

Question 1 of 15
1. Question
Question 1.
Complete the code:
x < c(1, 2,3) ________ = 5 x
Expected output:
[1] 1 5 3
Type in your answer below:
CorrectIncorrect 
Question 2 of 15
2. Question
Question 2.
Complete the code:
for(value in 1:5){ print(_______) }
Expected output:
[1] 1 [1] 2 [1] 3 [1] 4 [1] 5
Type in your answer below:
CorrectIncorrect 
Question 3 of 15
3. Question
Question 3.
Complete the code:
______ x
Expected output:
[1] "hello"
CorrectIncorrect 
Question 4 of 15
4. Question
Question 4.
Force = mass x acceleration.
If the car has a mass of 700 kg, and is driving with 0.05 m/s/s, find the force acting on the car.
mass = 700 kg
acceleration = 0.05 m/s/s
F = ?
Complete the code:
force < function(mass, acceleration){ mass*acceleration} ______ (________)
Expected output:
[1] 35
Type in your answer below:
Â
CorrectIncorrect 
Question 5 of 15
5. Question
Question 5.
Complete the code:
for (i in 1:10){ ____ (("calculate log "), log(i))}
Expected output:
calculate log 0 calculate log 0.693147180559945 calculate log 1.09861228866811 calculate log 1.38629436111989 calculate log 1.6094379124341 calculate log 1.79175946922805 calculate log 1.94591014905531 calculate log 2.07944154167984 calculate log 2.19722457733622 calculate log 2.30258509299405
CorrectIncorrect 
Question 6 of 15
6. Question
Question 6.
Compete the code:
x < 32 y < 74 x ____ y
Expected output:
[1] TRUE
Type in your answer below:
CorrectIncorrect 
Question 7 of 15
7. Question
Question7.
Complete the code:
x < 5 y < 5 x _____ y
Expected output:
[1] TRUE
Type in your answer below:
CorrectIncorrect 
Question 8 of 15
8. Question
Question 8.
The code below shows an example of a growing vector. Why is this considered to be a bad practice:
x < NUll for (i in 1:1000){ x< c(x, rnorm(1)) }
CorrectIncorrect 
Question 9 of 15
9. Question
Question 9.
Complete the code:
A = matrix(1:4, nrow = 2, byrow = TRUE) A [,1] [,2] [1,] 1 2 [2,] 3 4 A[_____]
Expected output:
[1] 3
Type in your answer below:
CorrectIncorrect 
Question 10 of 15
10. Question
Question 10.
Complete the code below:
x < 1:5 for (val in x) { if (val == 3){ _____ } print(val) }
Expected output:
[1] 1 [1] 2
Type in your answer below:
CorrectIncorrect 
Question 11 of 15
11. Question
Question 11.
The following code prompts the user to enter name and age, and then prints the greeting statement with the user’s age next year.
my.name < _____(prompt="Enter name: ") my.age < _____(prompt="Enter age: ") # convert character into integer my.age < as.integer(my.age) print(paste("Hi,", my.name, "next year you will be", my.age+1, "years old."))
What is the missing function in this code?
CorrectIncorrect 
Question 12 of 15
12. Question
Question 12.
You have a task to take a vector and evaluate it as either being positive or negative and then return a vector with 1 if it’s positive and 1 if it’s negative. You used
apply()
function, but your colleagues tell you it is better to use afor
loop for this task. Are they correct?CorrectIncorrect 
Question 13 of 15
13. Question
Question 13.
Complete the missing code:
day < "Monday" ____(day == "Monday"){ print("Your weekend is over!") }
Expected outcome:
[1] "Your weekend is over!"
Type in your answer below:
CorrectIncorrect 
Question 14 of 15
14. Question
Question 14.
What’s the output of the following code?
answer < function(x, y){ z < (x+y*2) if(z > 10) { return("Your output is greater than 10") } return(z) } answer(2, 4)
CorrectIncorrect 
Question 15 of 15
15. Question
Question 15.
Complete the code:
answer < function(x, y){ x**y } _______
Expected output:
[1] 16
Type in your answer below:
CorrectIncorrect