Introduction to R Programming for Data Science Week 3 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 Week 3


Practice Quiz

Q1. Which looping statement should you use if you want to continue to perform an operation if the value of an expression is true?
a. For Each loop
b. Do While loop
c. For loop
d. While loop

Answer: d. While loop


Q2. What happens if a user-defined function is missing the return statement?
a. The function returns an error.
b. The function returns the first evaluated expression it encounters and then immediately exits the function.
c. The function returns the last evaluated expression in the function.
d. The function returns a NULL value.

Answer: c. The function returns the last evaluated expression in the function.


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


Q3. Assume you have a variable called word_string that contains the string “The quick red fox jumped over the lazy dog.” Which function can you use to replace the word “dog” with the word “cat” in the word_string variable?
a. chartr()
b. substr()
c. strsplit()
d. nchar()

Answer: a. chartr()


Q4. Which of the following statements about regular expressions are true? Select two answers.
a. Regular expressions perform mathematical operations on numeric values.
b. Regular expressions evaluate a condition to determine if it is true or false.
c. Regular expressions are used to match patterns in strings and text.
d. Regular expressions are primarily used for data extraction.

Answer: c, d


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

See also  Introduction to R Programming for Data Science Week 2 Answers

Q5. How do you convert a UNIX date/time format to an R Date object?
a. Pass the UNIX date/time value to the as.Date() function.
b. Pass the UNIX date/time value to the as.POSIXct() function and then pass that value to the is.Date() function.
c. Pass the UNIX date/time value to the as.POSIXct() function and then pass that value to the as.Date() function.
d. Pass the UNIX date/time value to the is.Date() function.

Answer: c. Pass the UNIX date/time value to the as.POSIXct() function and then pass that value to the as.Date() function.


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


Q6. What type of statement should you add to your code if you know that an error or warning might occur?
a. Incorrect distractor
b. A catchError statement.
c. A tryCatch statement.
d. A tryError statement.

Answer: c. A tryCatch statement.


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


Graded Quiz

Q1. What is the result of the conditional statement 25 > 15 | 99 >= 100?
a. TRUE
b. FALSE

Answer: a. TRUE


Q2. How do you define a global variable in a function?
a. Use the -> assignment operator.
b. Use the <- assignment operator.
c. Use the <<- assignment operator.
d. Use the == assignment operator.

Answer: c. Use the <<- assignment operator.


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


Q3. 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?
a. stringr
b. tidyr
c. purrr
d. readr

See also  Introduction to R Programming for Data Science Week 4 Answers

Answer: a. stringr


Q4. Assume you have a data frame that contains a string variable called ‘phone’. The phone numbers in this variable appear in (###) ###-#### or ###-###-#### format. Which feature of R can you use to isolate the area code (the three numbers between the parentheses or the first three numbers)?
a. It is not possible to do this using R.
b. A regular expression.
c. A string operation.
d. A mathematical operation.

Answer: b. A regular expression.


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


Q5. When you convert a date in string format to a Date object, what information do you need to pass to the as.Date() function? Select two answers.
a. The number of days since January 1, 1970.
b. The UNIX format of the string.
c. The string containing the date.
d. The date format of the string.

Answer: c, d


Q6. What is the difference between an error and a warning in you R code?
a. An error halts code execution, while a warning does not.
b. A warning halts code execution, while an error does not.
c. You can catch an error, but you cannot catch a warning.
d. You can catch a warning, but you cannot catch an error.

Answer: a. An error halts code execution, while a warning does not.


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



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

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


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