1. Which looping statement should you use if you want to continue to perform an operation if the value of an expression is true?
For Each loop
Do While loop
2. What happens if a user-defined function is missing the return statement?
The function returns an error.
The function returns a NULL value.
The function returns the first evaluated expression it encounters and then immediately exits the function.
The function returns the last evaluated expression in the function.
3. 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?
4. Which of the following statements about regular expressions are true? Select two answers.
Regular expressions are primarily used for data extraction.
Regular expressions are used to match patterns in strings and text.
Regular expressions perform mathematical operations on numeric values.
Regular expressions evaluate a condition to determine if it is true or false.
5. How do you convert a UNIX date/time format to an R Date object?
Pass the UNIX date/time value to the is.Date() function.
Pass the UNIX date/time value to the as.POSIXct() function and then pass that value to the as.Date() function.
Pass the UNIX date/time value to the as.Date() function.
Pass the UNIX date/time value to the as.POSIXct() function and then pass that value to the is.Date() function.
6. What type of statement should you add to your code if you know that an error or warning might occur?
A tryCatch statement.
A tryError statement.
A catchError statement.
1. What is the result of the conditional statement 25 > 15 | 99 >= 100?
2. How do you define a global variable in a function?
Use the <- assignment operator.
Use the == assignment operator.
Use the <<- assignment operator.
Use the -> assignment operator.
3. 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?
4. 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 regular expression.
A string operation.
A mathematical operation.
It is not possible to do this using R.
5. 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.
The string containing the date.
The number of days since January 1, 1970.
The UNIX format of the string.
The date format of the string.
6. What is the difference between an error and a warning in you R code?
You can catch an error, but you cannot catch a warning.
You can catch a warning, but you cannot catch an error.
An error halts code execution, while a warning does not.
A warning halts code execution, while an error does not.