introduction to r programming for data science coursera answers week 4

Practice Quiz

1. Which package do you need to install before reading an Excel file in R?

  • No package is needed. This functionality is built into R.
  • readExcel
  • readxlsx
  • readxl

2. What is the purpose of the readLines() function?

  • Reads each text line (with a line break) in a text file and returns a character variable.
  • Reads each text line (with a line break) in a text file and returns a data frame.
  • Reads each text line (ending with a line break) in a text file and returns a character factor.
  • Reads each text line (ending with a line break) in a text file and returns a character vector.

3. Which data structure is more suitable to be exported into a text file rather than a .csv or Excel file?

  • String or characters
  • Matrices
  • Data frames
  • Datasets

4. Complete the sentence: _________________ is a communication protocol for fetching web resources for clients from servers on the Internet.

  • HTTP
  • REST
  • TCP
  • DNS

5. Complete the sentence: In an HTML page, if the and nodes have the same parent, , they are said to be ___________________ to each other.

  • Child nodes
  • Sibling nodes
  • Nested nodes
  • Root nodes

Graded Quiz

6. Assume you have read a .csv file into a data frame variable called employee. It has 20 rows of data and three variables: name, age, and title. What is the correct statement to use to return the fifth row of data in the name and title columns?

  • employee[5, 2:3]
  • employee[c(“name”, “title”), 5]
  • employee[2:3, 1:5]
  • employee[5, c(“name”, “title”)]

7. How do you return the number of characters in each paragraph of a text file that has been read into a character vector?

  • Use the nchar() function.
  • Use the length() function.
  • Use the scan() function.
  • Use the file.size() function.

8. Which package do you need to install before writing to an Excel file in R?

  • writexlsx
  • No package is needed. This functionality is built into R.
  • xlsx
  • writexl

9. 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 <-HEAD(“https://www.mysite.com”)
  • response <-POST(“https://www.mysite.com”)
  • response <-PUT(“https://www.mysite.com”)
  • response <- GET(“https://www.mysite.com”)

10. After reading an HTML page from a URL, what must you do to get the node from the root node?

  • Use the html_text() function to return the <html> node.
  • Use the html_node() function to return the <html> node.
  • Use the html_node() function to return the <body> as a child node of <html> node.
  • Use the html_text() function to return the <body> node of the HTML.

Leave a Reply