NEW
Font size
WorksheetsR Programming Challenge for BCA Students
Total questions: 20
Worksheet time: 10mins
What are the primary data structures in R?
Arrays
Strings
Vectors, Lists, Matrices, Data Frames, Factors
Tuples
How do you create a vector in R?
Use the c() function, e.g., c(1, 2, 3) for numeric vectors.
Use the array() function, e.g., array(1, 2, 3) for numeric vectors.
Create a list using list(1, 2, 3) instead of a vector.
Use the vector() function, e.g., vector(1, 2, 3) for numeric vectors.
What function is used to read a CSV file in R?
import.csv()
read.csv()
read.file()
load.csv()
Explain the difference between a list and a data frame in R.
A list is a collection of elements of different types, while a data frame is a table-like structure with columns of potentially different types but equal length.
A list is a fixed-size structure, while a data frame can change size dynamically.
A list and a data frame are the same, both are used for storing tabular data.
A list is always a numeric vector, while a data frame can only contain character data.
What is the purpose of the 'apply' family of functions in R?
To manage memory allocation in R.
To create new data structures in R.
To visualize data in R.
To apply a function to elements of data structures in R.
How do you handle missing values in R?
Use na.omit(), na.fill(), or imputation methods to handle missing values in R.
Ignore missing values and proceed with analysis without any adjustments.
Replace missing values with zeros only.
Use na.remove() to delete all rows with missing values.
What is the use of the 'ggplot2' package in R?
The 'ggplot2' package is used for statistical analysis in R.
The 'ggplot2' package is used for data visualization in R.
The 'ggplot2' package is used for machine learning in R.
The 'ggplot2' package is used for data cleaning in R.
How do you create a scatter plot using ggplot2?
geom_scatter(data, x_variable, y_variable)
ggplot(data) + add_points(x_variable, y_variable)
Use plot(data, x_variable, y_variable)
Use ggplot(data, aes(x = x_variable, y = y_variable)) + geom_point()
What is the syntax for a basic for loop in R?
for (i in 1:10) { print(i) }
for (i = 1; i <= 10; i++) { print(i) }
for i in 1 to 10 { print(i) }
foreach (i in 1:10) { print(i) }
How do you define a function in R?
A function in R is defined using the syntax: function_name <- function(parameters) { # function body }.
In R, a function is defined as: define function_name(parameters) { # code }
A function in R is defined using the syntax: function(parameters) { # function body }.
Functions in R are created with the command: create_function(function_name, parameters)
What is the scope of a variable in R?
The scope of a variable in R is always global.
Variables in R can only be defined within functions.
The scope of a variable in R is determined by its data type.
The scope of a variable in R can be local or global, depending on where it is defined.
Explain the concept of factors in R.
Factors in R are only used for numerical data.
Factors in R are a type of function that performs calculations.
Factors in R are exclusively for time series data.
Factors in R are categorical variables that store data as integers with corresponding character levels.
What statistical test would you use to compare means between two groups?
Mann-Whitney U test
t-test
Chi-square test
ANOVA
How do you perform a linear regression analysis in R?
Utilize the cor() function to find correlations.
Use lm() function to fit a linear model and summary() to analyze results.
Apply the t.test() function for regression analysis.
Use the plot() function to visualize data only.
What is the purpose of the 'summary' function in R?
To perform linear regression analysis.
To create visualizations of data.
To provide a summary of statistical properties of an object.
To calculate the mean of a dataset.
How can you customize the aesthetics of a ggplot2 plot?
You can customize aesthetics using functions like scale_color_manual(), theme(), and labs() in ggplot2.
Aesthetics cannot be customized in ggplot2 plots.
You can only change colors using scale_fill_brewer() in ggplot2.
You must use base R plotting functions to customize ggplot2 aesthetics.
What is the difference between a character vector and a numeric vector in R?
A character vector is used for logical operations; a numeric vector is used for string manipulations.
A character vector contains text strings; a numeric vector contains numbers.
A character vector contains numbers; a numeric vector contains text strings.
Both character and numeric vectors can only contain integers.
How do you install a package in R?
Use install.packages('package_name')
Use add.package('package_name')
Install package_name using RStudio
Run setup.packages('package_name')
What is the significance of the 'set.seed' function in R?
It is used to create data frames in R.
It ensures reproducibility of random number generation in R.
It generates random numbers without any control.
It automatically installs packages in R.
How do you create a bar chart using ggplot2?
Create a bar chart with barplot(data$categorical_variable) function.
Use ggplot(data, aes(y = categorical_variable)) + geom_line() to create a bar chart.
Use plot(data, type = 'h') to create a bar chart.
Use ggplot(data, aes(x = categorical_variable)) + geom_bar() to create a bar chart.
