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
d) Nothing will print
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
b) Missing Data
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.
3. R language is a dialect of which of the following languages?
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.
4. R language has superficial similarity with _________
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?
a <- c(1,” a”, FALSE)
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.
6. What is the length of b?
b <- 2:7
Explanation: Length of b  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)
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?
a) Numeric, Integer
b) Integer, Numeric
c) Integer, Integer
d) Numeric, Numeric
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?
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?
d) column name cannot be set for a data frame
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.