Tuesday , June 18 2024
Breaking News

R for Data Science Cognitive Class Exam Quiz Answers

R for Data Science Cognitive Class Certification Answers

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

  • Logical
  • Numeric
  • Character
  • All of the above

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

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

Question 3: 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

Question 1: 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 2: 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 3: 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))

Question 1: 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 2: 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 3: Which of the following would you use to check the class of the object, myobject?

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

Question 1: 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 2: 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 3: 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)

Question 1: 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 2: 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 3: 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.

Question 1: 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 2: 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 3: How would you get the average of: ratings <- c(8.0, 8.5, 9.0)

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

Question 4: 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 5: 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 6: 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 7: 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 8: 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 9: 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 10: In R, x <- 1 is the same as x == 1

  • True
  • False

Question 11: 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 12: 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 13: 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 14: 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 15: 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

Introduction to R for Data Science

“Introduction to R for Data Science” is a beginner-friendly guide to utilizing the R programming language for data analysis and visualization. R is a powerful open-source language commonly used by statisticians and data analysts for its extensive libraries and packages tailored for data manipulation, statistical modeling, and visualization.

Here’s an outline of what an introduction to R for Data Science might cover:

  1. Introduction to R:
    • What is R?
    • Why use R for data science?
    • Installing R and RStudio (an integrated development environment for R).
  2. Basic Operations:
    • Data types (numeric, character, logical, etc.).
    • Variables and assignments.
    • Arithmetic operations.
    • Working with vectors and matrices.
  3. Data Structures:
    • Vectors: single-dimensional arrays.
    • Matrices: multi-dimensional arrays.
    • Lists: collections of objects.
    • Data frames: tables of data with rows and columns (similar to datasets in spreadsheets).
  4. Data Import and Export:
    • Importing data from different file formats (CSV, Excel, etc.).
    • Exporting data to various formats.
  5. Data Manipulation:
    • Subsetting data.
    • Filtering and sorting data.
    • Adding, removing, and renaming columns.
    • Handling missing data.
  6. Statistical Analysis:
    • Summary statistics (mean, median, standard deviation, etc.).
    • Hypothesis testing.
    • Linear regression.
  7. Data Visualization:
    • Basic plotting functions.
    • Scatter plots, histograms, box plots, etc.
    • Customizing plots with titles, labels, colors, etc.
    • Using packages like ggplot2 for more advanced and customizable visualizations.
  8. Introduction to Packages:
    • Overview of popular R packages for data science (e.g., dplyr, tidyr, ggplot2).
    • Installing and loading packages.
    • Using packages to extend R’s functionality for specific tasks.
  9. Introduction to R Markdown:
    • Creating dynamic documents with R Markdown.
    • Combining R code, visualizations, and text in a single document.
    • Generating reports and presentations.
  10. Case Studies and Projects:
    • Applying R to real-world datasets.
    • Solving data science problems using R.
    • Building small projects to reinforce learning.
  11. Additional Resources:
    • Books, online courses, and tutorials for further learning.
    • Communities and forums for R users to seek help and collaborate.

About Clear My Certification

Check Also

Controlling Hadoop Jobs using Oozie Cognitive Class Exam Quiz Answers

Enroll Here: Controlling Hadoop Jobs using Oozie Cognitive Class Exam Quiz Answers Controlling Hadoop Jobs …

Leave a Reply

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