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!

Q61

Q61 Which dplyr function is used to summarize multiple values into a single value?

A

summarize()

B

collect()

C

condense()

D

reduce()

Q62

Q62 What is the purpose of the group_by() function in dplyr?

A

To split a data frame into groups based on one or more variables

B

To arrange groups in a specific order

C

To merge two groups

D

To compare groups

Q63

Q63 What does the arrange() function in dplyr do when applied to a data frame?

A

It arranges the rows in descending order

B

It arranges the rows based on the values in one or more columns

C

It randomly arranges the rows

D

It converts the rows into columns

Q64

Q64 Which function in dplyr is best for changing the names of columns in a data frame?

A

rename()

B

alter()

C

change()

D

modify()

Q65

Q65 How can you combine two data frames vertically using dplyr?

A

bind_rows()

B

merge()

C

concat()

D

union()

Q66

Q66 What dplyr function would you use to join two data frames by columns when the columns have different names in each frame?

A

join()

B

merge()

C

full_join()

D

left_join(), with the by argument specifying the matching columns

Q67

Q67 How do you create a new column in a data frame that calculates the logarithm of an existing column in dplyr?

A

mutate(log_column = log(existing_column))

B

create(log_column = log(existing_column))

C

add(log_column = log(existing_column))

D

set(log_column = log(existing_column))

Q68

Q68 Why might changes made by mutate() in dplyr not appear in the original data frame?

A

mutate() does not modify in place

B

mutate() syntax errors

C

mutate() used on an empty data frame

D

mutate() is not supported for data frames

Q69

Q69 What could cause summarize() in dplyr to return fewer rows than expected when using a group_by() statement?

A

Incorrect grouping

B

Exclusion of NA values in groups

C

Overly restrictive aggregation functions

D

Summarize is case-sensitive

Q70

Q70 What is ggplot2 primarily used for in R?

A

Database management

B

Statistical analysis

C

Data visualization

D

Machine learning

Q71

Q71 Which ggplot2 function is used to create a scatter plot?

A

ggsave()

B

ggplot() + geom_point()

C

ggplot() + geom_line()

D

ggplot() + geom_histogram()

Q72

Q72 In ggplot2, what does the aes() function specify?

A

Data sources

B

Aesthetics mappings

C

Plot dimensions

D

Saving options

Q73

Q73 What is the purpose of the facet_wrap() function in ggplot2?

A

To wrap text labels

B

To create multi-panel plots

C

To apply themes to plots

D

To adjust plot margins

Q74

Q74 How does theme() function affect a ggplot2 plot?

A

It changes the data source for the plot

B

It modifies aesthetic attributes

C

It alters plot appearance by modifying non-data components

D

It adjusts data alignment

Q75

Q75 Which function saves a ggplot2 plot to a file?

A

ggsave()

B

ggplot_save()

C

save_ggplot()

D

export()

Q76

Q76 To add a linear regression line to a scatter plot in ggplot2, which function would you use?

A

geom_smooth(method = "lm")

B

geom_line()

C

geom_path()

D

geom_segment()

Q77

Q77 How do you add labels to the axes in a ggplot2 plot?

A

labs(x = "X-axis label", y = "Y-axis label")

B

annotate()

C

labels()

D

axis_lab()

Q78

Q78 What does setting the alpha parameter in ggplot2 accomplish?

A

It adjusts the plot's aspect ratio

B

It changes the data points' color

C

It sets the transparency of elements

D

It scales the axes

Q79

Q79 If a ggplot2 plot appears empty, what might be a common issue?

A

Missing data

B

Incorrect data mappings in aes()

C

Data not loaded into R

D

All listed issues

Q80

Q80 What could cause the colors in a ggplot2 plot to not display as expected?

A

Incorrect color names in the aes() function

B

Incompatible color values

C

Misconfigured display settings

D

Both incorrect color names and incompatible color values

Q81

Q81 What function is used to calculate the mean of a numeric vector in R?

A

mean()

B

average()

C

median()

D

sum()

Q82

Q82 Which function in R provides a summary of the central tendency, dispersion, and shape of a dataset’s distribution?

A

summary()

B

describe()

C

info()

D

data_summary()

Q83

Q83 In R, what does the sd() function calculate?

A

Standard deviation

B

Sum of deviations

C

Sample distribution

D

Standard data

Q84

Q84 What is the purpose of the cor() function in R?

A

To perform correlation analysis between two or more variables

B

To compare datasets

C

To merge data frames

D

To create plots

Q85

Q85 How do you test for normality of a dataset in R?

A

Using the norm.test() function

B

Using the shapiro.test() function

C

Using the normality() function

D

Using the gauss.test() function

Q86

Q86 What R function is used to generate a linear model for regression analysis?

A

lm()

B

linear()

C

regression()

D

model()

Q87

Q87 How can you generate a frequency table of a categorical variable in R?

A

table()

B

freq()

C

categorical()

D

group()

Q88

Q88 What is the R command to calculate the median of a numeric vector?

A

median()

B

middle()

C

center()

D

mean()

Q89

Q89 How do you perform a t-test to compare the means of two groups in R?

A

t.test(data$group1, data$group2)

B

compare.means(data$group1, data$group2)

C

groups.ttest(data$group1, data$group2)

D

test.t(data$group1, data$group2)

Q90

Q90 What might be the reason if lm() fails to fit a model in R?

A

Incorrect data types

B

Missing data

C

Both incorrect data types and missing data

D

None of the above

ad verticalad vertical
ad