R Programming Questions and Answers – Basics – 2

This set of R Programming Language Multiple Choice Questions & Answers (MCQs) focuses on “Basics – 2”.

1. What is output of getOption(“defaultPackages”) in R studio?
a) Installs a new package
b) Shows default packages in R
c) Error
d) Nothing will print
View Answer

Answer: b
Explanation: There are base packages (which come with R automatically), and contributed packages. The base packages are maintained by a select group of volunteers, called R Core. In addition to the base packages, there are over ten thousand additional contributed packages written by individuals all over the world.

2. What will be the output of the following R code?

    x <- c(3, 7, NA, 4, 7)
    y <- c(5, NA, 1, 2, 2)
    x + y

a) Symbol
b) Missing Data
c) 5
d) 15.5
View Answer

Answer: b
Explanation: Missing data are a persistent and prevalent problem in many statistical analyses, especially those associated with the social sciences. R reserves the special symbol NA to represent missing data. Ordinary arithmetic with NA value gives NA’s (addition, subtraction, etc.) and applying a function to a vector that has a NA in it will usually give a NA.
advertisement
advertisement

3. R language is a dialect of which of the following languages?
a) S
b) C
c) MATLAB
d) SAS
View Answer

Answer: a
Explanation: The R language is a dialect of S which was designed in the 1980s. Since the early 90’s the life of the S language has gone down a rather winding path. The scoping rules for R are the main feature that makes it different from the original S language.
Note: Join free Sanfoundry classes at Telegram or Youtube

4. R language has superficial similarity with _________
a) C
b) Python
c) MATLAB
d) SAS
View Answer

Answer: a
Explanation: The language syntax has a superficial similarity with C, but the semantics are of the FPL (functional programming language) variety with stronger affinities with Lisp and APL. There are many syntaxes in C, which are closely resembled with R.

5. What is the mode of ‘a’ in the following R code?

advertisement
     a <- c(1,” a”, FALSE)

a) Numeric
b) Character
c) Integer
d) Logical
View Answer

Answer: b
Explanation: All three elements can be expressed as a character. Both paste() and cat() will printout text to the console by combining multiple character vectors together. The original data are formatted as character strings so we convert them to R’s Date format for easier manipulation.
advertisement

6. What is the length of b?

b <- 2:7

a) 4
b) 5
c) 6
d) 0
View Answer

Answer: c
Explanation: Length of b [1] 2 3 4 5 6 7 is 6. We can also create an empty list of a prespecified length with the vector() function. Data frames are represented as a special type of list where every element of the list has to have the same length.

7. What is the mode of b in the following R code?

     b <- c(TRUE, TRUE, 1)

a) Numeric
b) Character
c) Integer
d) Logical
View Answer

Answer: a
Explanation: All the elements in ‘b’ can be expressed in numeric. Both paste() and cat() will printout text to the console by combining multiple character vectors together. The original data are formatted as character strings so we convert them to R’s Data format for easier manipulation.

8. What are the typeof(x) and mode(x) in the following R syntax?

     x<-1:3

a) Numeric, Integer
b) Integer, Numeric
c) Integer, Integer
d) Numeric, Numeric
View Answer

Answer: b
Explanation: Here typeof() tells about the data type. They are an important type of object in R and are used in a variety of statistical modelling applications. You can determine an object’s type with the typeof function.

9. How many atomic vector types does R have?
a) 5
b) 6
c) 8
d) 10
View Answer

Answer: b
Explanation: R language has 6 atomic data types. They are logical, integer, real, complex, string (or character) and raw. There is also a class for “raw” objects, but they are not commonly used directly in data analysis.

10. What is the function to set row names for a data frame?
a) row.names()
b) colnames()
c) col.names()
d) column name cannot be set for a data frame
View Answer

Answer: a
Explanation: row.names() is the function to set row names for a data frame. Data frames have a special attribute called row.names, which indicate information about each row of the data frame.

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.