R Programming Questions and Answers – Dates and Times

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

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

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

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

advertisement
advertisement
 log(-1)

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

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

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

4. Warnings are generated by the _________ function.
a) warning()
b) error()
c) run()
d) message()
View Answer

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

Answer: a
Explanation: Dates stored in the POSIX format are date/time values (like dates with the chron library), but also allow modification of time zones.

advertisement

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

Answer: a
Explanation: The function seems to work fine. No errors, warnings, or messages.

advertisement

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

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

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

To practice all areas of R Programming Language, Here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.