By: Prof. Dr. Fazal Rehman | Last updated: November 25, 2024
Which of the following functions is used to read a CSV file into R?
(A) read.csv()
(B) csv.read()
(C) load.csv()
(D) read.table()
Answer: (A) read.csv()2. What does the apply() function do in R?
(A) Applies a function to a data frame or matrix margin (rows or columns)
(B) Applies a function to all elements in a list
(C) Applies a statistical test to the data
(D) Applies a function to a specific subset of data based on conditions
Answer: (A) Applies a function to a data frame or matrix margin (rows or columns)3. Which of the following functions can be used to create a linear model in R?
(A) lm()
(B) model()
(C) lmfit()
(D) linear.model()
Answer: (A) lm()4. What is the purpose of the str() function in R?
(A) Displays the structure of an R object
(B) Converts a string into a factor variable
(C) Creates a string from variables in a data frame
(D) Converts an R object into a string
Answer: (A) Displays the structure of an R object5. How do you handle missing values in a data frame in R?
(A) Use the na.rm argument in functions like sum(), mean()
(B) Use the na.omit() function to remove missing values
(C) Use complete.cases() to identify rows without missing values
(D) All of the above
Answer: (D) All of the above6. In R, what does the ggplot2 package primarily provide?
(A) Data manipulation functions
(B) Statistical models and tests
(C) A framework for creating data visualizations
(D) A set of machine learning tools
Answer: (C) A framework for creating data visualizations7. What is the primary purpose of the dplyr package in R?
(A) To create and manipulate statistical models
(B) To clean, filter, and summarize data efficiently
(C) To create machine learning algorithms
(D) To visualize data using various plotting techniques
Answer: (B) To clean, filter, and summarize data efficiently8. Which function would you use to generate a random sample of size n from a normal distribution in R?
(A) rnorm(n)
(B) runif(n)
(C) sample(n, size)
(D) random.sample(n)
Answer: (A) rnorm(n)9. What is the default method for computing the mean of a numeric vector in R?
(A) mean()
(B) median()
(C) sum() / length()
(D) avg()
Answer: (A) mean()9. In R, which function is used to concatenate two or more vectors or strings?