250+ TOP MCQs on Dates and Times and Answers

R Programming Language Multiple Choice Questions 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

Answer: b
Clarification: 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

Answer: d
Clarification: Programmers can create their own custom conditions if they want.

3. What would be the value of following R expression?

a) Warning in log(-1): NaNs produced
b) 1
c) Null
d) 0

Answer: a
Clarification: 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()

Answer: a
Clarification: 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

Answer: a
Clarification: 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

Answer: a
Clarification: 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

Answer: b
Clarification: 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

Answer: a
Clarification: You can’t do that test if x is a NA or NaN value.

Leave a Reply

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