r programming banner

R Programming Multiple Choice Questions (MCQs) and Answers

Master R Programming with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of R Programming concepts. Begin your placement preparation journey now!

Q31

Q31 Which function is most appropriate for adding a new column to a data frame in R?

A

append()

B

insert()

C

$ operator

D

add()

Q32

Q32 If a vector operation returns unexpected 'NA' values, what is a possible cause?

A

Missing data in vector

B

Data type mismatch in operations

C

Incorrect function use

D

All elements are NA

Q33

Q33 What could be the issue if accessing an element beyond the length of a vector doesn't return an error but returns NA?

A

Vector is defined to have extra length

B

Vector indexing starts at 0

C

Vector contains explicit NA values

D

An error in R's internal handling

Q34

Q34 When merging two data frames, why might some entries appear as 'NA'?

A

Missing matches in key columns

B

Incorrect data types

C

Syntax errors in merge function

D

All columns are incompatible

Q35

Q35 Which control structure allows repeating a set of commands a fixed number of times in R?

A

while loop

B

for loop

C

if-else statement

D

repeat loop

Q36

Q36 In R, what does the if statement do?

A

Executes a loop

B

Tests a condition and executes an associated block of code

C

Defines a function

D

Imports a package

Q37

Q37 What is the use of the break statement in R?

A

Terminates a loop or switch statement

B

Starts a new iteration of a loop

C

Skips the current iteration of a loop

D

Exits the program

Q38

Q38 Which statement is used in R to skip the current iteration of a loop and begin the next one?

A

continue

B

next

C

skip

D

break

Q39

Q39 How can you execute a block of code multiple times conditionally in R?

A

Using the if loop

B

Using the for loop

C

Using the while loop

D

Using the do loop

Q40

Q40 What is the purpose of the else if statement in R?

A

To specify a new condition to test, if the first condition is false

B

To exit a loop

C

To define a function

D

To repeat a condition

Q41

Q41 Which syntax correctly starts a for loop in R that iterates from 1 to 10?

A

for (i = 1 to 10) { }

B

for i in 1:10 { }

C

for (i in 1:10) { }

D

for i from 1 to 10 { }

Q42

Q42 How do you write an infinite loop in R?

A

while (true) { }

B

while (1) { }

C

Both A and B are correct

D

Neither A nor B are correct

Q43

Q43 What does the following loop do?
for (i in 1:5) print(i^2)

A

Prints the squares of numbers 1 to 5

B

Prints numbers from 1 to 5

C

Counts from 1 to 5

D

None of the above

Q44

Q44 In a while loop, what happens if the condition never becomes false?

A

The loop terminates after a set number of iterations

B

The loop continues indefinitely

C

The loop skips iterations

D

The loop throws an error

Q45

Q45 What is a common mistake when using nested loops in R?

A

Mismanaging loop counters

B

Using the wrong loop type

C

Not nesting loops correctly

D

Forgetting to close brackets

Q46

Q46 If a loop is supposed to run but doesn't start, what could be a potential issue?

A

The loop condition is initially false

B

The loop is improperly nested

C

There are syntax errors in the loop code

D

All of the above

Q47

Q47 Which function in R is used to install packages from CRAN?

A

install.packages()

B

get.packages()

C

load.packages()

D

add.packages()

Q48

Q48 What is a primary use of the library() function in R?

A

Create new libraries

B

Delete existing libraries

C

Load installed packages into the R session

D

Update libraries

Q49

Q49 In R, what is the purpose of the source() function?

A

To load data from external sources

B

To execute R scripts from files

C

To generate reproducible random numbers

D

To integrate R with other programming languages

Q50

Q50 What does the apply() function do in R?

A

Modifies data frames

B

Applies a function over the margins of an array or matrix

C

Creates graphical plots

D

None of the above

Q51

Q51 Which statement best describes the role of user-defined functions in R?

A

They replace all basic functions of R

B

They are only for advanced users

C

They allow customization of tasks

D

They are not recommended

Q52

Q52 What is the function set.seed() used for in R?

A

To establish the starting point for loops

B

To control the reproducibility of random number generation

C

To seed the R environment with data

D

To initialize package settings

Q53

Q53 How do you create a simple function in R that takes one argument x and returns x squared?

A

def square(x) { return xx }

B

function(x) { return xx }

C

function(x) { xx }

D

square <- function(x) { x*x }

Q54

Q54 How do you ensure that a package is loaded only if it is already installed in R?

A

if (require(package)) library(package)

B

if (library(package))

C

if (installed.packages(package)) library(package)

D

if (require(package))

Q55

Q55 When defining a function in R, what is the effect of setting a default value for an argument?

A

It makes the argument optional

B

It makes the function faster

C

It limits the function to specific data types

D

It creates a constant

Q56

Q56 If a function fails because an argument is not correctly passed, what could be the probable issue?

A

Incorrect data type of argument

B

Missing function definition

C

Syntax error in function call

D

Incompatible library version

Q57

Q57 What should you check if a user-defined function in R isn't recognized in your script?

A

Whether the function is defined after it's called

B

Whether the package containing the function is loaded

C

Whether the script file is corrupted

D

Whether the R version is outdated

Q58

Q58 Which dplyr function is used to select columns from a data frame?

A

select()

B

filter()

C

arrange()

D

mutate()

Q59

Q59 What does the mutate() function in dplyr do?

A

Adds new variables to a data frame and preserves existing ones

B

Filters rows based on conditions

C

Sorts a data frame

D

Summarizes complex calculations

Q60

Q60 How does the filter() function in dplyr determine which rows to keep in a data frame?

A

By evaluating conditions set on columns

B

By matching patterns in row names

C

By comparing row indices

D

By data type of rows

ad verticalad vertical
ad