Introduction to R Programming for Data Science Week 4 Final Exam Answers

  1. After installing and calling the httr library in R, which command can you use to request information about https://www.google.com?    GET(“https://www.google.com/”)
  2. After installing and calling the httr library in R, which method should you use to update a resource?    PUT 
  3. After reading an HTML page from a URL, what must you do to get the <body> node from the root <html> node?   Use the html_node() function to return the <body> as a child node of <html> node.
  4. After you write code in an R script file or the R Console, what component of the R environment parses the code into objects in memory?  R Interpreter
  5. 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)?    5
  6. 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”?   isReviewGood(7.5, threshold = 7)
  7. Assume that the variable test_result contains the vector c(25, 35, 40, 50, 75).What is the result of the expression mean(test_result)?  45
  8. Assume that you have a data frame called employee that contains three variables: name, age, and title. If you want to return all the values in the title variable, what command should you use? employee$title
  9. 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?    “It” “misery” “The Shining”
  10. 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?    array(books_vector, dim = c(3, 2))
  11. Assume you have variable called employee that contains the expression list(name = “Juan”, age = 30). What is the correct command to change the contents of the age item to 35?  employee[“age”] <- 35
  12. Execution order does not matter when executing cells in a Jupyter notebook   False
  13. How do you define a global variable in a function?  Use the <<- assignment operator.
  14. 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  names == “Jimmy”
  15. 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?  sort(age)
  16. 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?     names(age)
  17. In R, variables are typically assigned using <−, but they can also be assigned using which of the following symbols?   =
  18. In R, what is the result of the function as.character(10.3)?   “10.3”
  19. In R, what is the result of the function as.integer(3.3)?   3
  20. In R, what is the result of the function as.numeric(TRUE)?  1
  21. In R, which command removes a variable from memory?   Rm
  22. In R, which command returns the first six elements of a data object such as a data frame?        Head
  23. In R, which command returns the last six elements of a data object such as a data frame?    Tail
  24. In R, which command should you use to insert a new row into a data frame?    Rbind
  25. In R, which command will output the data from the Nile built-in data set?    Nile
  26. In R, which command will read the file books-db.csv?   read.csv (books-db.csv)
  27. 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?   (150 – 90) \* 60
  28. R can perform several forms of statistical computation. What is an example of hypothesis testing?   Testing if the mean values of two groups are statistically different.
  29. What is a nominal factor?  A factor with no implied order
  30. What is the first step you must take before you can read an Excel spreadsheet in R?   Install the readxl library.
  31. What is the main difference between a matrix and an array?   A matrix must be two dimensional, but an array can be single, two dimensional, or more than two dimensional.
  32. What is the main reason to use the R language?  Statistical computation
  33. What is the result of the conditional statement 25 > 15 | 99 >= 100?  TRUE
  34. Which command in R would return the following numeric vector?   c(5:1)
  35. Which features of RStudio help facilitate code writing? Select two answers.   Syntax highlighting Code auto completion
  36. 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?   mult \<- function(x,y) { x \ * y }
  37. Which of the following is a typical way that developers use the R language?   Predictive analysis
  38. Which package do you need to install before writing to an Excel file in R?   xlsx
  39. You can use the str_sub() function to form a substring by counting back from the last position. This function is part of which package?   Stringr
  40. You want to get a resource by its URL using an HTTP request and assign the HTTP response containing status code, headers, response body to a response variable. Which function should you use?    response <- GET(“https://www.mysite.com”)
  41. In R, what is the result of the function as.numeric(TRUE)? 1
  42. In R, which command removes a variable from memory?   Rm
  43. Which command in R would return the following character vector? “James” “Anna” “Lucas” “Harrold”    c(“James”, “Anna”, “Lucas”, “Harrold”)
  44. In R, assume you have a vector named “age,” and each element in the vector is the age of one person in a group. The vector has the following content: 24 32 46 19. What will be the result if you issue the age[-2] command?  24 46 19
  45. In R, which command should you use to insert a new row into a data frame?   Rbind
  46. 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?   mult\ <- function(x,y) {x\*y}
  47. What is the first step you must take before you can read an Excel spreadsheet in R? Install the readxl library
  48. After installing and calling the httr library in R, which method should you use to send data to a server to create a resource?  POST
  49. You want to get a resource by its URL using an HTTP request and assign the HTTP response containing status code, headers, response body to a response variable. Which function should you use?    response <- GET(“https://www.mysite.com”)

Other Links:

Statistics Quiz

Networking Quiz

See other websites for quiz:

Check on QUIZLET

Check on CHEGG

Leave a Reply

Your email address will not be published. Required fields are marked *