Introduction to R Programming for Data Science Week 5 Final Answers

Course Name: Introduction to R Programming for Data Science

Course Link: Click Here

These are answers of Introduction to R Programming for Data Science Final Week 5


Q1. Which of the following is a typical way that developers use the R language?
a. Systems programming
b. Web page interactivity
c. Predictive analysis
d. Video game development5b

Answer: c. Predictive analysis


Q2. What is the main reason to use the R language?
a. Statistical computation
b. Web page interactivity
c. Predictive analysis
d. Data visualization

Answer: a. Statistical computation


Q3. In R, what is the result of the function as.character(10.3)?
a. TRUE
b. 10
c. “10.3”
d. NA

Answer: c. “10.3”


These are answers of Introduction to R Programming for Data Science Final Week 5


Q4. What is the first step you must take before you can read an Excel spreadsheet in R?
a. Run the c function.
b. Convert the spreadsheet’s dataset.
c. Install the readxl library.
d. Run the read_excel function.

Answer: c. Install the readxl library.


Q5. Assume that the function add is defined as follows:
add <- function(x,y) { (x + y) return (x – y) temp <<- (x * y) return (x / y) }
What will be the output if you issue the command add(10,5)?

a. 50
b. 15
c. 2
d. 5

Answer: d. 5


Q6. In R, variables are typically assigned using <−, but they can also be assigned using which of the following symbols?
a. =
b. ≠
c. -\>
d. <=

Answer: a. =


These are answers of Introduction to R Programming for Data Science Final Week 5


Q7. In R, which command returns the last six elements of a data object such as a data frame?
a. tail
b. floor
c. abs
d. head

Answer: a. tail


Q8. In R, assume you have a vector named “age,” and each element in the vector is the age of one person in a group. Which command must you use to reorder the ages from youngest to oldest?
a. call(age)
b. order(age)
c. rank(age)
d. sort(age)

Answer: d. sort(age)


Q9. In R, assume a character vector called “names” has the following contents:
“Harry” “Jimmy” “Tammy”
Which command would return the following logical vector?
FALSE TRUE FALSE

a. names == “Jimmy”
b. is.logical(names)
c. get(“names”)
d. TRUE \<_ “Jimmy”

Answer: a. names == “Jimmy”


These are answers of Introduction to R Programming for Data Science Final Week 5


Q10. In R, which command will output the data from the Nile built-in data set?
a. help(Nile)
b. Nile
c. data(Nile)
d. install.Nile

Answer: b. Nile


Q11. Assume that the function isReviewGood is defined as follows:
isReviewGood <- function(rating, threshold = 8) { if(rating < threshold){ return(“NO”) } else { return(“YES”) } }
Which of the following commands will return “YES”?

a. isReviewGood(rating, 9)
b. isReviewGood(return, threshold = 10)
c. isReviewGood(7.5, threshold = 7)
d. isReviewGood(6)

Answer: c. isReviewGood(7.5, threshold = 7)


Q12. In R, which command should you use to insert a new row into a data frame?
a. integrate
b. rbind
c. head
d. tail

Answer: b. rbind


These are answers of Introduction to R Programming for Data Science Final Week 5


Q13. In R, which command returns the first six elements of a data object such as a data frame?
a. tail
b. floor
c. abs
d. head

Answer: d. head


Q14. Which of the following blocks of R code properly defines a function that takes two numbers as input and returns the product of the two numbers multiplied together?
a. mult \<- function() { x \ * y }
b. mult \<- function(xy) { x \ * y }
c. mult \<- function(x,y) { x \ * y }
d. mult \<- function{ x \ * y }

Answer: c. mult \<- function(x,y) { x \ * y }


These are answers of Introduction to R Programming for Data Science Final Week 5


Q15. Which command in R would return the following numeric vector?
5 4 3 2 1

a. c(5:1)
b. c(1:5)
c. c(5-\>1)
d. c(1,2,3,4,5)

Answer: a. c(5:1)


Q16. In R, which command will read the file books-db.csv?
a. read.books-db.csv
b. read.csv (books-db.csv)
c. books-db.csv
d. return books-db.csv

Answer: b. read.csv (books-db.csv)


These are answers of Introduction to R Programming for Data Science Final Week 5


Q17. In R, which command removes a variable from memory?
a. detach
b. rm
c. drop
d. sd

Answer: b. rm


Q18. n R, what is the result of the function as.integer(3.3)?
a. 3
d. False
c. ‘3.3’
b. 3.3

Answer: a. 3


Q19. Assume the array books_array contains 6 elements. The array has three rows and two columns and appears as follows:
[,1] [,2] [1,] “It” “Dr. Sleep” [2,] “Misery” “Carrie” [3,] “The Shining” “The Mist”
If you input the books_array[,1] command, what will be the output?

a. “It”
b. “The Shining”
c. “It” “Dr. Sleep”
d. “It” “misery” “The Shining”

Answer: d. “It” “misery” “The Shining”


These are answers of Introduction to R Programming for Data Science Final Week 5


Q20. One movie is 150 minutes long, and another is 90 minutes long. Using R, which of the following commands would correctly calculate the difference in length, in seconds, between the two films?
a. (150 – 90 \* 60)
b. (150 – 90) \* 60
c. 150 – 90 \* 60
d. 150 – (90 \* 60)

Answer: b. (150 – 90) \* 60


Q21. Assume the variable books_vector is a vector that contains six elements. Which of the following commands creates an array of this vector with three rows and two columns?
a. array(books_vector, dim = c(3, 2))
b. array(c(books_vector), dim = (2, 3))
c. array(books_vector, dim = c(2, 3))
d. array(books_vector, dim = (3,2))

Answer: a. array(books_vector, dim = c(3, 2))


These are answers of Introduction to R Programming for Data Science Final Week 5


Q22. After installing and calling the httr library in R, which command can you use to request information about https://www.google.com?
a. BROWSE(“https://www.google.com/”)
b. GET(“https://www.google.com/”)
c. PATCH(“https://www.google.com/”)
d. PUT(“https://www.google.com/”)

Answer: b. GET(“https://www.google.com/”)


Q23. After installing and calling the httr library in R, which method should you use to update a resource?
a. BROWSE
b. GET
c. PUT
d. UPDATE

Answer: c. PUT


These are answers of Introduction to R Programming for Data Science Final Week 5


Q24. In R, what is the result of the function as.numeric(TRUE)?
a. 1
b. 4
c. FALSE
d. NA

Answer: a. 1


Q25. In R, assume you have a vector named “age,” and each element in the vector is the age of one person in a group. Which command must you use to map each person’s name to their respective age?
a. call(age)
b. sink(age)
c. names(age)
d. print(age)

Answer: c. names(age)


These are answers of Introduction to R Programming for Data Science Final Week 5



All weeks answers of Introduction to R Programming for Data Science: Click Here

These are answers of Introduction to R Programming for Data Science Final Week 5


These are answers of Introduction to R Programming for Data Science Final Week 5
The content uploaded on this website is for reference purposes only. Please do it yourself first.