Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

R for Data Science Quiz Answers – Cognitive Class

Get R for Data Science Quiz Answers

R is a powerful language for data analysis, data visualization, machine learning, statistics. Originally developed for statistical programming, it is now one of the most popular languages in data science. In this course, you’ll be learning about the basics of R, and you’ll end with the confidence to start writing your own R scripts.

But this isn’t your typical textbook introduction to R. You’re not just learning about R fundamentals, you’ll be using R to solve problems related to movies data. Using a concrete example makes the learning painless. You will learn about the fundamentals of R syntax, including assigning variables and doing simple operations with one of R’s most important data structures — vectors!

From vectors, you’ll then learn about lists, matrix, arrays and data frames. Then you’ll jump into conditional statements, functions, classes and debugging. Once you’ve covered the basics – you’ll learn about reading and writing data in R, whether it’s a table format (CSV, Excel) or a text file (.txt). Finally, you’ll end with some important functions for character strings and dates in R.

Enroll on Cognitive Class

Module 1 – R Basics

Question: Vectors in R can be which of the following types?

  • Logical
  • Numeric
  • Character
  • All of the above

Question: What would be the output in R given: c(1,2) == 1 ?

  • FALSE TRUE
  • TRUE FALSE
  • FALSE FALSE
  • TRUE TRUE

Question: How would you retrieve the items larger than 5 (as in 15 and 10) from the following vector: costs <- c(3, 15, 3, 10)?

  • costs[15,10]
  • costs[c(15,10)]
  • costs(costs > 5)
  • costs[costs > 5]
  • costs > 5

Module 2 – Data structures in R

Question: Give a 5 x 5 matrix object, movies, how would you retrieve the bottom-left item?

  • movies[1,5]
  • movies(5,5)
  • movies[5,1]
  • movies[5,5]
  • movies[“bottom-left”]

Question: Below we create a list for a student and his info. Select all the correct options can we use to retrieve his courses? john <- list(“studentid“ = 9, “age” = 18, “courses” = c(“Data Science 101”, “Data Science Methodology”))

  • john[“courses”]
  • john[3]
  • john$courses
  • All the above options are correct

Question: Select the correct code from the following options which produces the following result?

  • data.frame(“student” = c(“john”, “mary”), “id” = c(1, 2))
  • array(“student” = c(“john”, “mary”), “id” = c(1, 2))
  • data.frame(c(“john”, “mary”), c(1, 2))
  • data.frame(student = c(john, mary), id = c(1, 2))
  • list(“student” = c(“john”, “mary”), “id” = c(1, 2))

Module 3 – R programming fundamentals

Question: What output will the following produce?

    
chance_precipitation <- 0.80
if( chance_precipitation > 0.5 ) {
    print("Bring an umbrella") } else {
        print("Don't bring an umbrella")}
  • “Thunderstorm warning”
  • “Don’t bring an umbrella”
  • “Bring an umbrella”
  • Some sort of error

Question: Which of the following statements are true?

  • Using return() when writing a function is optional when you just want the result of the last line in the function to be the output of the function.
  • Using return() when writing a function is necessary even when you just want the result of the last line in the function to be the output of the function.
  • Using return() is useful when you want to produce outputs based on different conditions.
  • Using return() serves no purpose when you want to produce outputs based on different conditions.

Question: Which of the following would you use to check the class of the object, myobject?

  • class(myobject)
  • type(myobject)
  • class(object)
  • class[myobject]

Module 4 – Working with data in R

Question: What does CSV stand for, when talking about tabular data files?

  • Column-sorted values
  • Comma-separated values
  • Commonly-spaced values
  • Column-separated values
  • None of the above

Question: Which of the following are true?

  • read.csv() can be used to read in CSV files
  • You need to install libraries, such as the “readxl” library, to read Excel files into R
  • You can load specified datasets or list the available datasets using data()
  • You can write to a variety of filetypes, including .txt, .csv, .xls, .xlsx, and .Rdata.

Question: To get the number of characters in a character vector, char_vec, what function can you use?

  • nchar(char_vec)
  • numberOfCharacters[char_vec]
  • char_vec.nchar()
  • length(char_vec)

Module 5 – Strings and Dates in R

Question: How would you combine the individual words from the vector, hw, into a single string, “Hello World”?

hw <- c("Hello", "World")

  • paste(hw, collapse = ” “)
  • paste(“Hello”, “World”)
  • tolower(“Hello”, “World”)
  • c(hw[1], hw[2])
  • None of the above

Question: How would you convert the character string “2020-01-01” into a Date object in R?

  • as.Date(“2020-01-01”)
  • convertToDate(“2020-01-01”)
  • date(“2020-01-01”)
  • Sys.Date()

Question: What does the following regular expression pattern mean?

".*@.+"

  • Find matches containing an @ symbol where there is one or more characters before the @ symbol, and zero or more characters after the @ symbol.
  • Find matches containing an @ symbol where there is one or more characters before the @ symbol, and at least one character after the @ symbol.
  • Find matches containing an @ symbol where there is zero or more characters before the @ symbol, and at least one character after the @ symbol.
  • It’s actually a new emoticon.

Final Exam

Question: Which of the following will return TRUE?

  • 1 > 2
  • ”Apples” = “Bananas”
  • TRUE = FALSE
  • 2.1 in c(1.5, 3.14)
  • None of the above

Question: Which of the following will print out the numbers 1, 2, and 3 only?

  • for(num in c(1,2,3)) {print(num)}
  • c(1,2,3)
  • c(1:3)
  • c(0,1,2,3,4,5)[2:4]

Question: How would you get the average of: ratings <- c(8.0, 8.5, 9.0)

  • mean(“ratings”)
  • AVER(“rating”)
  • mean(ratings)
  • average[ratings]

Question: How would you convert the following character vector into an integer vector?

my_vector <- c("1992", "2016", "2012", "2018")

  • as.integer(my_vector)
  • as.numeric(my_vector)
  • tointeger(my_vector)
  • converttointeger(my_vector)

Question: If you know an error might occur, what can you do?

  • Think about why the error is happening and attempt to fix the code.
  • Catch the error using the tryCatch() function.
  • All of the above.
  • Give up entirely.

Question: You have a file, “november.csv”, in the directory, “/Documents/expenses/“. How do you read this file into R?

  • readLines(/Documents/expenses/november.csv)
  • read.csv(“/Documents/expenses/november.csv”)
  • read.csv(/Documents/expenses/november.csv)
  • read.csv(“november.csv”, folder = “Documents/expenses”, type = “csv”)
  • None of the above

Question: You opened a dataset and noticed a row showing Leonardo DiCaprio’s birthday as 153360000. What does it mean?

  • 153360000 is a UNIX timestamp; it is the number of seconds since 1970-01-01 00:00:00.
  • Leonardo DiCaprio was born on March 15, 1936 at 00:00.
  • The data is definitely corrupt.
  • Leonardo DiCaprio will be born in the year 153360000.

Question: The following code will produce which of the following outputs?

grep("milk.+", c("cow's milk", "milkshake", "milky", "cat", "milk1", "milk"), value = T)

  • “milkshake” “milky” “milk1”
  • 2 3 5 6
  • “milky” “milk1”
  • “milkshake” “milky” “milk1” “milk”
  • “cow’s milk” “milkshake” “milky” “cat” “milk1” “milk”

Question: You want to split a full name, “John Doe”, into a vector containing two elements: “John” and “Doe”. How would you do so?

fullname <- “John Doe”

  • unlist(strsplit(fullname, “ “))
  • strsplit(fullname, “ “)
  • None of the above.

Question: In R, x <- 1 is the same as x == 1

  • True
  • False

Question: Look at the code below. How many levels does the factor, drinks, have?

drinks <- factor(c(“tea”, “coffee”, “soft drink”, “tea”, “hot chocolate”, “hot chocolate”, “coffee”))

  • 1
  • 3
  • 5
  • 7
  • None of the above

Question: To remove an existing column, “firstname”, from a data frame named “people”, which of the following code should you use?

  • firstname <- NA
  • people$firstname <- FALSE
  • people(“firstname”) <- NA
  • people$firstname <- NULL

Question: To retrieve the third row of an array named “myarray”, which of the following code should you use?

  • myarray[3]
  • myarray[,3]
  • myarray(row = “third”)
  • myarray[3,]

Question: How would you get the average of the third column of a data frame named “df”?

  • mean(df[3,])
  • mean(df[,3])
  • mean(df[3])
  • df[,3].mean()

Question: What is the expected output of the following script?

    
myfunc <- function(x, y = 2){
x = x + 10
y = y + 100
return(y)
}
myfunc(3)
  • 102
  • 3
  • 13
  • 2
Conclusion:

We hope you know the correct answers to R for Data Science If Queslers helped you to find out the correct answers then make sure to bookmark our site for more Course Quiz Answers.

If the options are not the same then make sure to let us know by leaving it in the comments below.

Course Review:

In our experience, we suggest you enroll in this and gain some new skills from Professionals completely free and we assure you will be worth it.

This course is available on Cognitive Class for free, if you are stuck anywhere between quiz or graded assessment quiz, just visit Queslers to get all Quiz Answers and Coding Solutions.

More Courses Quiz Answers >>

Building Cloud Native and Multicloud Applications Quiz Answers

Accelerating Deep Learning with GPUs Quiz Answers

Blockchain Essentials Cognitive Class Quiz Answers

Leave a Reply

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