0% found this document useful (0 votes)
4 views5 pages

R Programming MCQs IA2 Sem2

The document contains a series of multiple-choice questions (MCQs) focused on R programming, specifically covering topics related to data manipulation and visualization using packages like dplyr and ggplot2. Each question presents options related to functions and their purposes, such as unite(), mutate(), and various ggplot2 geoms. The questions aim to test knowledge on data transformation, summarization, and visualization techniques in R.

Uploaded by

Amol MJ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

R Programming MCQs IA2 Sem2

The document contains a series of multiple-choice questions (MCQs) focused on R programming, specifically covering topics related to data manipulation and visualization using packages like dplyr and ggplot2. Each question presents options related to functions and their purposes, such as unite(), mutate(), and various ggplot2 geoms. The questions aim to test knowledge on data transformation, summarization, and visualization techniques in R.

Uploaded by

Amol MJ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

R-Programming MCQs

Q1. What does the unite() function in tidyr do?

a. Joins two datasheets based on common variables


b. Combines multiple columns into a single column
c. Merges rows with similar values
d. Converts data from long format to wide format

Q2. In ggplot2, which geom would be most appropriate for visualizing the distribution of a
continuous variable?

a. Geom_bar()
b. Geom_boxplot()
c. Geom_histogram()
d. Geom_point()

Q3. When using the pipe operator (%>%) with dplyr functions, what does it allow you to do?

a. Pass the result of one function as the first argument to the next function
b. Execute multiple functions simultaneously
c. Skip error checking between function calls
d. Create temporary variables to store intermediate results

Q4. When using mutate() to create a new variable based on conditional logic, which function
is most appropriate?

a. If_else()
b. Switch()
c. For()
d. While()

Q5. Which of the following ggplot2geoms would most appropriate for comparing
distribution across different categories?

a. Geom_violin()
b. Geom_line()
c. Geom_point()
d. Geom_file()

Q6. What is the main difference between slice_min() and slice_max() in dply?

a. Slice_min() selects the first n rows while slice_max() selects the last n rows
b. Slice_min() selects rows with minimum values of a variable while slice_max() selects
rows with maximum values
c. Slice_min() works with numeric data while slice_max()works with character data
d. Slice_min() can only be used after group_by() while slice_max() can be used
independently
R-Programming MCQs
Q7. In the context of data transformation, which statement about mutate() and transmute()
is correct?

a. They are identical functions with different names


b. Mutate() adds new variables and keeps existing ones, while transmule() only keeps
the new variables
c. Mutate() works with grouped data while transmute() doesn’t
d. Mutate() is for numeric variables while transmute() is for character variables

Q8. When using the slice() function in dplyr, what does slice(5 10) do?

a. Selects rows where a variable has values between 5 and 10


b. Selects the 5th through 10th rows in the dataset
c. Creates a subset with 5 to 10 random rows
d. Returns rows where the row number is divisible by values between 5 and 10

Q9. When using the mutate() function in dplyr, which of the following statement is TRUE?

a. It can only create new variables but cannot modify existing ones
b. It can create new variables and modify existing ones simultaneously
c. It can only be used after a group_by() operation
d. It permanently alters the original dataset

Q10. In a ggplot2 visualization, what is the correct order of layers in terms of how they are
processed?

a. Data, mapping, geom


b. Mapping, data, geom
c. Data, geom, mapping
d. Geom, data,mapping

Q11. When creating a scatter plot with ggplot2, which aesthetic mappings are essential?

a. X and y
b. X, y, and color
c. X, y, and size
d. X, y, and shape

Q12. What would the code df %>% group_by(category) &>% slice_head(n=3) accomplish?

a. Select the top 3 rows from the entire dataset


b. Select the top 3 rows for each unique category value
c. Select 3 random rows from each category
d. Select the first 3 categories in the dataset

Q13. When using summarise() with group_by(), which of the following would calculate the
median value of a variable for each group?
R-Programming MCQs
a. Summarise(median = mean(variable))
b. Summarise(median = median(variable))
c. Summarise(median = max(variable) – min(variable))
d. Summarise(median = sum(variable)/n())

Q14. When using pivot_wider() in tidyr, which parameter specifies the column that contains
the values to be used for the new column names?

a. Values_from
b. Names_from
c. Names_to
d. Values_to

Q15. Which tidyr function would you use to split a column containing date values in the
format YYYY-MM-DD into separate year, month and and column?

a. Pivot_wider()
b. Separate()
c. Unite()
d. Extract()

Q16. What is the primary purpose of the group_by() function in dplyr?

a. To arrange data in according or descending order


b. To create subnets of data based on unique values in specified columns
c. To join multiple datasets together
d. To remove duplicate rows from a dataset

Q17. When creating a bivariate plot in ggplot2, which aesthetic mapping would you use to
represent a third categorial variable?

a. Color or fill
b. Size
c. Alpha
d. All of the above can be used

Q18. When creating a visualization in ggplot2, which function adds a title to the plot?

a. Labs(title=’My Title’)
b. Title(‘My Title’)
c. Add_title(‘My Title’)
d. Ggplot(title = (‘My Title’)

Q19. In the context of tidyr, what does the pivot_longer() function primarily do?

a. Converts data from wide format to long format


b. Converts data from long format to wide format
R-Programming MCQs
c. Splits a single column into multiple columns
d. Combines multiple columns into a single columnso

Q20. In tidyr, what is the primary purpose of the separate() function?

a. To split a database into multiple datasets


b. To divide a column containing multiple values into separate columns
c. To remove missing values from a dataset
d. To separate numeric and character columns

Q21. In tidyr, what would happen if you use pivot_longer() on a dataset where some of the
columns you’re trying to pivot contain different data types?

a. The function will automatically convert all values to character type


b. The function will raise an error and stop
c. The function will only pivot columns with compatible data types
d. The function will use NA for incompatible values

Q22. When using summarise() with grouped data, which function would calculate the
number of observations in each group?

a. Count()
b. N()
c. Tally()
d. Size()

Q23. Which of the following dplyr verbs would you use to extract the top 5 values from a
dataset based on a specific variable?

a. Slice_max()
b. Filter()
c. Top_n()
d. Arrange()

Q24. In ggplot2, what is the function of the facet_wrap() command?

a. To create separate plots for each level of a categorial variable


b. To wrap text in the plot labels
c. To adjust the aspect ration of the plot
d. To combine multiple plots into one

Q25. What is the primary difference between slice_sample() and sample_n() in dplyr?

a. Slice_sample() can work with grouped data while sample_n() cannot


b. Slice_sample() is deprecated while sample_n() is the recommended function
c. Sample_n() selects a fixed number while slice_sample() can select a proportion
d. There is no difference: they are aliases of the same function
R-Programming MCQs
Q26. When using summarise() after group_by(), what happens to the grouped variables?

a. They are completely removed from the resulting dataset


b. They are retained with one row per group
c. They are automatically preserved as grouping variables
d. They are combined into a single list variable

Q27. Which parameter in pivot_wider() specifies the column containing the values that will
fill the new columns?

a. Values_from
b. Names_from
c. Names_to
d. Values_to

Q28. When using dplyr’s summarize() function with multiple summary statistics, what
happens to the result?

a. Each statistic: creates a separate dataset that must be joined later


b. All statistics are calculated and presented in a single row per group
c. The function can only compute one statistics at a time
d. The function automatically arranges the statistics in descending order

Q29. Which ggplot2 geom would be most appropriate for visualizing changes in a variable
over time?

a. Geom_line()
b. Geom_bar()
c. Geom_point()
d. Geom_boxplot()

Q30. When using pivot_longer() in tidyr, which parameter allows you to specify which
column should be pivoted?

a. Cols
b. Names_to
c. Values_to
d. Id_cols

You might also like