This set of R Programming Language Multiple Choice Questions & Answers (MCQs) focuses on “Dates and Times”.
1. _________ is an indication that a fatal problem has occurred and execution of the function stops.
a) message
b) error
c) warning
d) message & warning
View Answer
Explanation: Errors are produced by the stop() function.
2. Point out the correct statement?
a) R has a number of ways to indicate to you that something’s not right
b) Executing any function in R may result in the condition
c) “condition” is a generic concept for indicating that something unexpected has occurred
d) All of the mentioned
View Answer
Explanation: Programmers can create their own custom conditions if they want.
3. What would be the value of following R expression?
log(-1)
a) Warning in log(-1): NaNs produced
b) 1
c) Null
d) 0
View Answer
Explanation: This warning lets you know that taking the log of a negative number results in a NaN value because you can’t take the log of negative numbers.
4. Warnings are generated by the _________ function.
a) warning()
b) error()
c) run()
d) message()
View Answer
Explanation: warning is an indication that something is wrong but not necessarily fatal; execution of the function continues.
5. Point out the correct statement?
a) POSIX represents a portable operating system interface, primarily for UNIX systems
b) There are different levels of indication that can be used, ranging from mere notification to fatal error
c) The default input format for POSIX dates consists of the month, followed by the year and day, separated by slashes or dashes
d) R don’t have any way to indicate to you that something’s not right
View Answer
Explanation: Dates stored in the POSIX format are date/time values (like dates with the chron library), but also allow modification of time zones.
6. What will be the output of the following R code?
> printmessage <- function(x) { + if(x > 0) + print("x is greater than zero") + else + print("x is less than or equal to zero") + invisible(x) + } > printmessage(1)
a) Error
b) Warning
c) Messages
d) 0
View Answer
Explanation: The function seems to work fine. No errors, warnings, or messages.
7. To get the current date, the _______ function will return a Date object which can be converted to a different class if necessary.
a) Sys.Time
b) Sys.Date
c) Sys.DateTime
d) DateTime
View Answer
Explanation: The POSIXlt class stores date/time values as a list of components (hour, min, sec, mon, etc.) making it easy to extract these parts.
8. What will be the output of the following R code?
> printmessage <- function(x) { + if(x > 0) + print("x is greater than zero") + else + print("x is less than or equal to zero") + invisible(x) + } > printmessage(NA)
a) Error
b) Warning
c) Messages
d) Null
View Answer
Explanation: You can’t do that test if x is a NA or NaN value.
Sanfoundry Global Education & Learning Series – R Programming Language.
Here’s the list of Best Books in R Programming Language.
- Check Information Technology Books
- Check R Programming Books
- Practice Programming MCQs
- Apply for Programming Internship