Data Analysis using R
Unit - I
1. Which of the following is used in R to create a vector?
a) c()
b) vector()
c) list()
d) array()
Answer: a) c()
2. Which function in R is used to read a CSV file?
a) [Link]()
b) [Link]()
c) scan()
d) [Link]()
Answer: b) [Link]()
3. What is the output of the following R expression: 2 + 3 * 4?
a) 20
b) 14
c) 12
d) 10
Answer: b) 14
4. Which function in R can be used to create a matrix?
a) matrix()
b) array()
c) mat()
d) matrix_create()
Answer: a) matrix()
5. What is the result of applying the sum() function to a matrix in R?
a) Sum of all elements
b) Sum of columns
c) Sum of rows
d) Sum of each diagonal element
Answer: a) Sum of all elements
6. Which of the following is used to apply a function to each element of a list in
R?
a) apply()
b) lapply()
c) sapply()
d) tapply()
Answer: b) lapply()
7. What does the factor() function do in R?
a) Converts a character vector into a numeric vector
b) Converts a numeric vector into a factor with levels
c) Converts a numeric matrix into a factor
d) Converts an object into a matrix
Answer: b) Converts a numeric vector into a factor with levels
8. Which of the following functions is used for conditional execution in R?
a) ifelse()
b) if()
c) while()
d) for()
Answer: a) ifelse()
9. Which of the following is used for looping in R?
a) loop()
b) repeat()
c) for()
d) each()
Answer: c) for()
10. How can you read data from an Excel file in R?
a) [Link]()
b) [Link]()
c) [Link]()
d) import_excel()
Answer: a) [Link]()
11. Which of the following R functions is used for matrix multiplication?
a) prod()
b) %*%
c) multiply()
d) matmul()
Answer: b) %*%
12. What is the purpose of the t() function in R?
a) Transpose a matrix
b) Test for null values
c) Calculate the determinant of a matrix
d) Multiply two matrices
Answer: a) Transpose a matrix
13. Which function is used to calculate the mean of a vector in R?
a) avg()
b) mean()
c) sum()
d) median()
Answer: b) mean()
14. Which of the following methods is used for string manipulation in R?
a) string_manipulate()
b) charFunctions()
c) substr()
d) text()
Answer: c) substr()
15. Which function is used to apply a function over subsets of a vector or list
in R?
a) apply()
b) tapply()
c) lapply()
d) sapply()
Answer: b) tapply()
16. How can you define a custom function in R?
a) function_name()
b) def function_name()
c) create_function()
d) function function_name()
Answer: d) function function_name()
17. Which function returns the unique elements of a vector in R?
a) unique()
b) distinct()
c) filter()
d) setdiff()
Answer: a) unique()
18. Which function would you use to sort a vector in R?
a) order()
b) sort()
c) rank()
d) arrange()
Answer: b) sort()
19. How do you check for missing values in R?
a) missing()
b) [Link]()
c) [Link]()
d) [Link]()
Answer: c) [Link]()
20. Which function in R would you use to combine multiple values into a
single string?
a) paste()
b) concatenate()
c) combine()
d) merge()
Answer: a) paste()
Unit – IV
1. What is a data frame in R?
a) A type of matrix
b) A list of vectors of equal length
c) A collection of data in columns, each of which can be a different type
d) A vector of matrices
Answer: c) A collection of data in columns, each of which can be a different type
2. Which function is used to create a data frame in R?
a) [Link]()
b) [Link]()
c) frame()
d) [Link]()
Answer: a) [Link]()
3. Which of the following R functions can be used to view the first few rows of
a data frame?
a) head()
b) tail()
c) view()
d) summary()
Answer: a) head()
4. What does the str() function do when applied to a data frame in R?
a) Prints the summary statistics
b) Prints the structure of the data frame
c) Summarizes missing values
d) Sorts the data frame
Answer: b) Prints the structure of the data frame
5. Which function is used to access specific columns in a data frame?
a) col()
b) df$column_name
c) column()
d) df[ , ]
Answer: b) df$column_name
6. How can you access the second row and first column of a data frame in R?
a) df[1, 2]
b) df[2, 1]
c) df[2][1]
d) df[1, 1]
Answer: b) df[2, 1]
7. What is the function used to order a data frame by a specific column in R?
a) order()
b) sort()
c) [Link]()
d) arrange()
Answer: a) order()
8. What does the summary() function do for a data frame in R?
a) Summarizes the statistics of each column
b) Lists all the rows
c) Provides a graphical summary
d) Displays the structure of the data
Answer: a) Summarizes the statistics of each column
9. Which function in R loads a data frame from a CSV file?
a) [Link]()
b) [Link]()
c) [Link]()
d) [Link]()
Answer: b) [Link]()
10. How can you access the column names of a data frame in R?
a) colnames(df)
b) names(df)
c) df$names()
d) Both a and b
Answer: d) Both a and b
11. Which of the following will return the last few rows of a data frame in R?
a) head()
b) tail()
c) bottom()
d) last()
Answer: b) tail()
12. What does the dim() function return when applied to a data frame?
a) The number of columns
b) The number of rows
c) A tuple of rows and columns
d) A summary of data
Answer: c) A tuple of rows and columns
13. How can you add a new column to a data frame in R?
a) df$new_column <- values
b) df$add(column)
c) df$insert(column)
d) [Link](df, column)
Answer: a) df$new_column <- values
14. What does the [Link]() function check for?
a) If an object is a vector
b) If an object is a data frame
c) If an object is a matrix
d) If an object contains missing values
Answer: b) If an object is a data frame
15. Which function would you use to check for missing values in a data frame?
a) na()
b) [Link]()
c) missing()
d) null()
Answer: b) [Link]()
16. How can you filter rows in a data frame based on a condition in R?
a) df[condition]
b) filter(df, condition)
c) subset(df, condition)
d) All of the above
Answer: d) All of the above
17. Which function would you use to combine two data frames by rows?
a) merge()
b) cbind()
c) rbind()
d) bind_rows()
Answer: c) rbind()
18. What does the nrow() function return when applied to a data frame in R?
a) The number of columns
b) The number of rows
c) The total number of elements
d) A summary of the rows
Answer: b) The number of rows
19. How would you save a data frame to a CSV file in R?
a) [Link](df, "[Link]")
b) [Link](df, "[Link]")
c) [Link](df, "[Link]")
d) [Link](df, "[Link]")
Answer: a) [Link](df, "[Link]")
20. How do you combine multiple columns into a single column in a data
frame in R?
a) paste()
b) combine()
c) merge()
d) rbind()
Answer: a) paste()
Unit – V
1. Which function in R gives a quick statistical summary (min, max, mean,
median, quartiles) of a dataset?
a) summary()
b) mean()
c) describe()
d) sd()
Answer: a
2. Which measure of central tendency is most resistant to outliers?
a) Mean
b) Median
c) Variance
d) Mode
Answer: b
3. In R, the function var(x) computes:
a) Standard deviation
b) Variance
c) Range
d) Median absolute deviation
Answer: b
4. Which descriptive statistic is best for detecting data spread?
a) Mean
b) Mode
c) Standard Deviation
d) Median
Answer: c
Section B: Base Graphics
5. Which function is used to create a bar chart in base R?
a) plot()
b) barplot()
c) hist()
d) boxplot()
Answer: b
6. A boxplot is primarily used to:
a) Show correlation between two variables
b) Display distribution and outliers
c) Show frequencies of categories
d) Plot time series data
Answer: b
7. Which plot type is most suitable for visualizing categorical data distribution?
a) Boxplot
b) Bar chart
c) Line plot
d) Heatmap
Answer: b
8. To display monthly sales over a year, the best plot is:
a) Histogram
b) Line plot
c) Boxplot
d) Heatmap
Answer: b
9. Which function in base R is used to create a boxplot?
a) plot()
b) barplot()
c) boxplot()
d) hist()
Answer: c
10.A heatmap is most useful for:
a) Showing missing values only
b) Displaying relationships in categorical data
c) Visualizing matrix data like correlations
d) Plotting frequency counts
Answer: c
Section C: Customization
[Link] base R plots, the argument main = "Title" is used to:
a) Change axis labels
b) Add a title to the plot
c) Adjust legend position
d) Set background color
Answer: b
[Link] parameter is used to change the x-axis label in base R plots?
a) ylab
b) xlab
c) main
d) title
Answer: b
[Link] a scatter plot, the pch argument controls:
a) Line thickness
b) Point shape
c) Axis scale
d) Plot color
Answer: b
[Link] function in base R is used to add a legend to a plot?
a) legend()
b) [Link]()
c) text()
d) title()
Answer: a
[Link] plot two lines in different colors on the same graph, you can use:
a) plot() and barplot()
b) plot() and lines()
c) barplot() twice
d) hist() and lines()
Answer: b
Section D: Spotting Problems
[Link] in a dataset are best detected using:
a) Bar chart
b) Boxplot
c) Heatmap
d) Line plot
Answer: b
[Link] in data is best visualized using:
a) Histogram
b) Scatter plot
c) Bar chart
d) Heatmap
Answer: a
[Link] a dataset shows extreme skewness, which transformation is commonly
applied?
a) Square root or log transformation
b) Median scaling
c) Outlier removal only
d) Z-score standardization
Answer: a
[Link] visualization would help detect correlations among numeric
variables?
a) Histogram
b) Boxplot
c) Heatmap
d) Bar chart
Answer: c
[Link] values in a dataset may appear in plots as:
a) Continuous smooth lines
b) Gaps or NA values
c) Extra legends
d) Changed axis labels
Answer: b