R Programming McQs

Q.1 To create a data frame in R, which function should you use?

A. data.frame()
B. createDataFrame()
C. new.data.frame()
D. df()

Shw me The Right Answer

Answer . A 

Q.2 How do you convert a vector to a list in R?

A, as.list()
B. to.list()
C. convert.list()
D. make.list()

Shw me The Right Answer

Answer . A 

Q.3 What function would you use to create a vector of all even numbers from 2 to 20 in R?

A. seq(2, 20, by=2)
B. even(2, 20)
C. range(2, 20, step=2)
D. vec_even(2, 20)

Shw me The Right Answer

Answer . A 

Q.4 Which function would you use to check if an object is a data frame in R?

A. is.data.frame()
B. is.list()
C. is.vector()
D. is.frame()

Shw me The Right Answer

Answer . A 

Q.5 What is the main difference between a list and a vector in R?

A. Lists can only contain numeric data
B. Vectors can contain mixed data types
C. Lists are 1-dimensional
D. Lists can contain elements of different types

Shw me The Right Answer

Answer . D 

Q.6 How do you access the 3rd element of a vector named ‘vec’ in R?

A. vec[3]
B. vec(3)
C. vec{3}
D. vec<3>

Shw me The Right Answer

Answer . A 

Q.7 In R, what is a data frame?

A. A special type of list
B. A special type of matrix
C. A low-level data structure
D. A non-relational database

Shw me The Right Answer

Answer . A 

Q.8 Which function is used to combine elements into a list in R?

A. combine()
B. list()
C. merge()
D. collect()

Shw me The Right Answer

Answer . B 

Q.9 What type of data structure is a vector in R?

A. Single-element
B. Homogeneous
C. Heterogeneous
D. Multi-dimensional

Shw me The Right Answer

Answer . B 

Q.10 If an R script is not executing as expected and there is no error message, what might be the issue?

A. The script is saved in the wrong format
B. There is an infinite loop
C. The code is commented out
D. All libraries are not loaded

Shw me The Right Answer

Answer . C 

Q.11 What is a common reason for the error message “unexpected symbol” in R?

A. Missing comma
B. Incorrect function name
C. Syntax error in code
D. Unquoted string

Shw me The Right Answer

Answer . C 

Q.12 What function is used to check whether a variable is a matrix in R?

A. is.matrix()
B. is.array()
C. is.vector()
D. is.frame()

Shw me The Right Answer

Answer . A 

Q.13 Which symbol in R is used to end a line of code?

A. ;
B. .
C. ,
D. |

Shw me The Right Answer

Answer . A 

Q.14 How do you start an R script file?

A. With a function declaration
B. With libraries loading
C. With any code
D. With a shebang line

Shw me The Right Answer

Answer . C 

Q.15 Which function in R can be used to create a vector of consecutive integers from 1 to 10?

A. c(1:10)
B. seq(1, 10)
C. vector(1, 10)
D. range(1, 10)

Shw me The Right Answer

Answer . A 

Q.16 Which function would you use to convert a character string to uppercase in R?

A. toUpper()
B. toUpperCase()
C. upperCase()
D. toupper()

Shw me The Right Answer

Answer . D 

Q.17 How do you declare a constant in R?

A. Using the const keyword
B. By assigning a value once
C. Using the define keyword
D. By using the constant() function

Shw me The Right Answer

Answer . B 

Q.18 What is the default data type of a number in R, like 42?

A. integer
B. logical
C. numeric
D. character

Shw me The Right Answer

Answer . C 

Q.19 Which operator is used to assign values in R?

A. <-
B. =
C. =>
D. :=

Shw me The Right Answer

Answer . A 

Q.20 In R, which function is used to check the data type of a variable?

A. type()
B. typeof()
C. datatype()
D. varType()

Shw me The Right Answer

Answer . B 

Q.21 Which data type in R is used to store true or false values?

A. integer
B. logical
C. character
D. double

Shw me The Right Answer

Answer . B 

Q.22 What symbol is used in R for commenting out a line of code?

A. #
B. //
C. —
D. %

Shw me The Right Answer

Answer . A 

Q.23 What function in R can be used to generate a sequence of numbers?

A. seq()
B. gen()
C. createSequence()
D. listNumbers()

Shw me The Right Answer

Answer . A 

Q.24 What type of data analysis is R particularly well-suited for?

A. Real-time
B. Exploratory
C. Big Data
D. Operational

Shw me The Right Answer

Answer . B 

Q.25 What was R based on?

A. C++
B. S
C. Java
D. Python

Shw me The Right Answer

Answer . B 

Q.26 R is part of which project that aims to provide software for statistical analysis?

A. The R Foundation
B. The R Project for Statistical Computing
C. Open Source Project
D. GNU Project

Shw me The Right Answer

Answer . B 

Q.27 Which IDE is most commonly used with R for data analysis?

A. Visual Studio Code
B. Jupyter Notebook
C. RStudio
D. Atom

Shw me The Right Answer

Answer . C 

Q.28 R is part of the software environment for which kind of computing?

A. Quantum
B. Statistical
C. Cloud
D. Distributed

Shw me The Right Answer

Answer . B 

Q.29 Which of the following is a core feature of R?

A. GUI development
B. Web programming
C. Statistical computing
D. Mobile development

Shw me The Right Answer

Answer . C 

Q.30 What type of programming language is R?

A. Statistical
B. General-purpose
C. Scripting
D. Object-oriented

Shw me The Right Answer

Answer . A 

Q.31 How does the filter() function in dplyr determine which rows to keep in a data frame?

A. By evaluating conditions set on columns
B. By matching patterns in row names
C. By comparing row indices
D. By data type of rows

Shw me The Right Answer

Answer . A 

Q.32 What does the mutate() function in dplyr do?

A. Adds new variables to a data frame and preserves existing ones
B. Filters rows based on conditions
C. Sorts a data frame
D. Summarizes complex calculations

Shw me The Right Answer

Answer . A 

Q.33 Which dplyr function is used to select columns from a data frame?

A. select()
B. filter()
C. arrange()
D. mutate()

Shw me The Right Answer

Answer . A 

Q.34 What should you check if a user-defined function in R isn’t recognized in your script?

A. Whether the function is defined after it’s called
B. Whether the package containing the function is loaded
C. Whether the script file is corrupted
D. Whether the R version is outdated

Shw me The Right Answer

Answer . A 

Q.35 If a function fails because an argument is not correctly passed, what could be the probable issue?

A. Incorrect data type of argument
B. Missing function definition
C. Syntax error in function call
D. Incompatible library version

Shw me The Right Answer

Answer . A 

Q.36 When defining a function in R, what is the effect of setting a default value for an argument?

A. It makes the argument optional
B. It makes the function faster
C. It limits the function to specific data types
D. It creates a constant

Shw me The Right Answer

Answer . A 

Q.37 How do you ensure that a package is loaded only if it is already installed in R?

A. if (require(package)) library(package)
B. if (library(package))
C. if (installed.packages(package)) library(package)
D. if (require(package))

Shw me The Right Answer

Answer . D 

Q.38 How do you create a simple function in R that takes one argument x and returns x squared?

A. def square(x) { return xx }
B. function(x) { return xx }
C. function(x) { xx }
D. square <- function(x) { x*x }

Shw me The Right Answer

Answer . D 

Q.39 What is the function set.seed() used for in R?

A. To establish the starting point for loops
B. To control the reproducibility of random number generation
C. To seed the R environment with data
D. To initialize package settings

Shw me The Right Answer

Answer . B 

Q.40 Which statement best describes the role of user-defined functions in R?

A. They replace all basic functions of R
B. They are only for advanced users
C. They allow customization of tasks
D. They are not recommended

Shw me The Right Answer

Answer . C 

Q.41 What does the apply() function do in R?

A. Modifies data frames
B. Applies a function over the margins of an array or matrix
C. Creates graphical plots
D. None of the above

Shw me The Right Answer

Answer . B 

Q.42 In R, what is the purpose of the source() function?

A. To load data from external sources
B. To execute R scripts from files
C. To generate reproducible random numbers
D. To integrate R with other programming languages

Shw me The Right Answer

Answer . B 

Q.43 What is a primary use of the library() function in R?

A. Create new libraries
B. Delete existing libraries
C. Load installed packages into the R session
D. Update libraries

Shw me The Right Answer

Answer . C 

Q.44 Which function in R is used to install packages from CRAN?

A. install.packages()
B. get.packages()
C. load.packages()
D. add.packages()

Shw me The Right Answer

Answer . A 

Q.45 If a loop is supposed to run but doesn’t start, what could be a potential issue?

A. The loop condition is initially false
B. The loop is improperly nested
C. There are syntax errors in the loop code
D. All of the above

Shw me The Right Answer

Answer . A 

Q.46 What is a common mistake when using nested loops in R?

A. Mismanaging loop counters
B. Using the wrong loop type
C. Not nesting loops correctly
D. Forgetting to close brackets

Shw me The Right Answer

Answer . A 

Q.47 In a while loop, what happens if the condition never becomes false?

A. The loop terminates after a set number of iterations
B. The loop continues indefinitely
C. The loop skips iterations
D. The loop throws an error

Shw me The Right Answer

Answer . B 

Q.48 What does the following loop do?
for (i in 1:5) print(i^2)

A. Prints the squares of numbers 1 to 5
B. Prints numbers from 1 to 5
C. Counts from 1 to 5
D. None of the above

Shw me The Right Answer

Answer . A 

Q.49 How do you write an infinite loop in R?

A. while (true) { }
B. while (1) { }
C. Both A and B are correct
D. Neither A nor B are correct

Shw me The Right Answer

Answer . C 

Q.50 Which syntax correctly starts a for loop in R that iterates from 1 to 10?

A. for (i = 1 to 10) { }
B. for i in 1:10 { }
C. for (i in 1:10) { }
D. for i from 1 to 10 { }

Shw me The Right Answer

Answer . C 

Q.51 What is the purpose of the else if statement in R?

A. To specify a new condition to test, if the first condition is false
B. To exit a loop
C. To define a function
D. To repeat a condition

Shw me The Right Answer

Answer . A 

Q.52 How can you execute a block of code multiple times conditionally in R?

A. Using the if loop
B. Using the for loop
C. Using the while loop
D. Using the do loop

Shw me The Right Answer

Answer . C 

Q.53 Which statement is used in R to skip the current iteration of a loop and begin the next one?

A. continue
B. next
C. skip
D. break

Shw me The Right Answer

Answer . B 

Q.54 What is the use of the break statement in R?

A. Terminates a loop or switch statement
B. Starts a new iteration of a loop
C. Skips the current iteration of a loop
D. Exits the program

Shw me The Right Answer

Answer . A 

Q.55 In R, what does the if statement do?

A. Executes a loop
B. Tests a condition and executes an associated block of code
C. Defines a function
D. Imports a package

Shw me The Right Answer

Answer . B 

Q.56 Which control structure allows repeating a set of commands a fixed number of times in R?

A. while loop
B. for loop
C. if-else statement
D. repeat loop

Shw me The Right Answer

Answer . B 

Q.57 When merging two data frames, why might some entries appear as ‘NA’?

A. Missing matches in key columns
B. Incorrect data types
C. Syntax errors in merge function
D. All columns are incompatible

Shw me The Right Answer

Answer . A 

Q.58 What could be the issue if accessing an element beyond the length of a vector doesn’t return an error but returns NA?

A. Vector is defined to have extra length
B. Vector indexing starts at 0
C. Vector contains explicit NA values
D. An error in R’s internal handling

Shw me The Right Answer

Answer . C 

Q.59 If a vector operation returns unexpected ‘NA’ values, what is a possible cause?

A. Missing data in vector
B. Data type mismatch in operations
C. Incorrect function use
D. All elements are NA

Shw me The Right Answer

Answer . A 

Q.60 Which function is most appropriate for adding a new column to a data frame in R?

A. append()
B. insert()
C. $ operator
D. add()

Shw me The Right Answer

Answer . C 

Q.61 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

Shw me The Right Answer

Answer . A 

Q.62 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)

Shw me The Right Answer

Answer . A 

Q.63 What is the R command to calculate the median of a numeric vector?

A. median()
B. middle()
C. center()
D. mean()

Shw me The Right Answer

Answer . A 

Q.64 How can you generate a frequency table of a categorical variable in R?

A. table()
B. freq()
C. categorical()
D. group()

Shw me The Right Answer

Answer . A 

Q.65 What R function is used to generate a linear model for regression analysis?

A. lm()
B. linear()
C. regression()
D. model()

Shw me The Right Answer

Answer . A 

Q.66 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

Shw me The Right Answer

Answer . B 

Q.67 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

Shw me The Right Answer

Answer . A 

Q.68 In R, what does the sd() function calculate?

A. Standard deviation
B. Sum of deviations
C. Sample distribution
D. Standard data

Shw me The Right Answer

Answer . A 

Q.69 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()

Shw me The Right Answer

Answer . A 

Q.70 What function is used to calculate the mean of a numeric vector in R?

A. mean()
B. average()
C. median()
D. sum()

Shw me The Right Answer

Answer . A 

Q.71 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

Shw me The Right Answer

Answer . A 

Q.72 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

Shw me The Right Answer

Answer . B 

Q.73 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

Shw me The Right Answer

Answer . C 

Q.74 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()

Shw me The Right Answer

Answer . A 

Q.75 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()

Shw me The Right Answer

Answer . A 

Q.76 Which function saves a ggplot2 plot to a file?

A. ggsave()
B. ggplot_save()
C. save_ggplot()
D. export()

Shw me The Right Answer

Answer . A 

Q.77 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

Shw me The Right Answer

Answer . C 

Q.78 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

Shw me The Right Answer

Answer . B 

Q.79 n ggplot2, what does the aes() function specify?

A. Data sources
B. Aesthetics mappings
C. Plot dimensions
D. Saving options

Shw me The Right Answer

Answer . B 

Q.80 Which ggplot2 function is used to create a scatter plot?

A. ggsave()
B. ggplot() + geom_point()
C. ggplot() + geom_line()
D. ggplot() + geom_histogram()

Shw me The Right Answer

Answer . B 

Q.81 What is ggplot2 primarily used for in R?

A. Database management
B. Statistical analysis
C. Data visualization
D. Machine learning

Shw me The Right Answer

Answer . C 

Q.82 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

Shw me The Right Answer

Answer . A 

Q.83 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

Shw me The Right Answer

Answer . A 

Q.84 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))

Shw me The Right Answer

Answer . A 

Q.85 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

Shw me The Right Answer

Answer . D 

Q.86 How can you combine two data frames vertically using dplyr?

A. bind_rows()
B. merge()
C. concat()
D. union()

Shw me The Right Answer

Answer . A 

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

A. rename()
B. alter()
C. change()
D. modify()

Shw me The Right Answer

Answer . A 

Q.88 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

Shw me The Right Answer

Answer . B 

Q.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

Shw me The Right Answer

Answer . A 

Q.90 Which dplyr function is used to summarize multiple values into a single value?

A. summarize()
B. collect()
C. condense()
D. reduce()

Shw me The Right Answer

Answer . A 

Q.91 Which function is used to get the current date and time in R?

A. now()
B. Sys.Date()
C. Sys.time()
D. current()

Shw me The Right Answer

Answer . C 

Q.92 When using tryCatch(), how can you capture and analyze the error object?

A. error = function(e) { print(e) }
B. catch = function(e) { analyze(e) }
C. errorHandler(e) { inspect(e) }
D. tryError(e) { log(e) }

Shw me The Right Answer

Answer . A 

Q.93 How can you debug an R script that runs without error but produces incorrect results?

A. Use print statements to inspect variables
B. Use a step-through debugger
C. Check for logical errors
D. All of the above

Shw me The Right Answer

Answer . A 

Q.94 If you encounter an “object not found” error in R, what is a likely cause?

A. Misspelled variable name
B. Incorrect function call
C. Package not loaded
D. All of the above

Shw me The Right Answer

Answer . A 

Q.95 How can you use debug() to step through a function named my_func in R?

A. debug(my_func); my_func()
B. step(my_func)
C. trace(my_func)
D. watch(my_func)

Shw me The Right Answer

Answer . A 

Q.96 How do you use the tryCatch() function to handle errors in R?

A. tryCatch(expr, error = function(e) { … })
B. tryCatch(expr, silent = TRUE)
C. try(expr)
D. catch(expr)

Shw me The Right Answer

Answer . A 

Q.97 Which function in R can be used to provide custom error messages?

A. stop()
B. error()
C. alert()
D. throw()

Shw me The Right Answer

Answer . A 

Q.98 What does the traceback() function do in R?

A. Shows the call stack leading to the error
B. Provides detailed error descriptions
C. Fixes the error automatically
D. Logs the error to a file

Shw me The Right Answer

Answer . A 

Q.99 What is the primary purpose of the try() function in R?

A. To attempt execution of code that might fail without stopping the entire script
B. To handle errors silently
C. To debug code
D. To improve code performance

Shw me The Right Answer

Answer . A 

Q.100 How can you avoid potential scoping issues in R functions when using global variables?

A. Always use <<- operator
B. Prefix global variables with global::
C. Avoid using global variables
D. Use local variables with the same name

Shw me The Right Answer

Answer . B 

Q.101 If a variable in a function is not found in the current environment, what is R’s next step in finding it?

A. R throws an error
B. R searches in the global environment
C. R searches in the parent environment
D. R returns NULL

Shw me The Right Answer

Answer . C 

Q.102 How can you access the parent environment of a given environment env in R?

A. parent.env(env)
B. env$parent
C. parent(environment)
D. get.parent(env)

Shw me The Right Answer

Answer . A 

Q.103 How do you list all objects in the current environment?

A. ls()
B. objects()
C. list()
D. all_objects()

Shw me The Right Answer

Answer . A 

Q.104 How do you create a new environment in R and assign a variable to it?

A. new.env(); e$a <- 1
B. env(); e$a <- 1
C. create.env(); e$a <- 1
D. new.environment(); e$a <- 1

Shw me The Right Answer

Answer . A 

Q.105 What does the <<- operator do in R?

A. Assigns a value in the current environment
B. Assigns a value in the global environment
C. Assigns a value in the parent environment
D. None of the above

Shw me The Right Answer

Answer . C 

Q.106 Which environment is at the top of the environment hierarchy in R?

A. Base environment
B. Global environment
C. Empty environment
D. Parent environment

Shw me The Right Answer

Answer . C 

Q.107 How does R determine the value of a variable when it is used in a function?

A. By checking global variables only
B. By searching the function’s environment and then parent environments
C. By checking the global environment first
D. By looking only in the base environment

Shw me The Right Answer

Answer . B 

Q.108 What is an environment in R?

A. A collection of data types
B. A collection of packages
C. A collection of symbol-value pairs
D. A collection of functions

Shw me The Right Answer

Answer . C 

Q.109 Why might read.table() return an error when reading a file that includes different data types?

A. The function expects uniform data types
B. Incorrect delimiter used
C. File contains improper formatting
D. Both the first and second options

Shw me The Right Answer

Answer . A 

Q.110 If write.csv() fails to save a data frame with error in R, what might be a common cause?

A. Incorrect file path
B. File is open in another program
C. Both reasons
D. None of the above

Shw me The Right Answer

Answer . C 

Q.111 How can you connect to and read from a text file that is continuously being updated, in R?

A. file(“log.txt”, “r”) and then use readLines()
B. open(“log.txt”, “r”) and use readText()
C. connect(“log.txt”) and use getText()
D. link(“log.txt”, “read”)

Shw me The Right Answer

Answer . A 

Q.112 What is the correct way to read an Excel file into R using the readxl package?

A. read_excel(“data.xlsx”)
B. load_excel(“data.xlsx”)
C. excel_read(“data.xlsx”)
D. get_excel(“data.xlsx”)

Shw me The Right Answer

Answer . A 

Q.113 Which function would you use to read a JSON file into R?

A. read.json()
B. fromJSON()
C. json()
D. load.json()

Shw me The Right Answer

Answer . B 

Q.114 How do you save an R data frame as a tab-separated values file?

A. write.table(df, “data.tsv”, sep=”\t”)
B. save.table(df, “data.tsv”, sep=”\t”)
C. write.csv(df, “data.tsv”, sep=”\t”)
D. output.tsv(df, “data.tsv”, sep=”\t”)

Shw me The Right Answer

Answer . A 

Q.115 What is the main difference between read.csv() and read.csv2() in R?

A. The former is used for reading large files, the latter for small files
B. The former uses comma as delimiter, the latter uses semicolon
C. The former supports UTF-8 encoding, the latter does not
D. There is no difference

Shw me The Right Answer

Answer . B 

Q.116 In R, what does the read.table() function do?

A. Reads data stored in a table format
B. Creates a table from vector data
C. Visualizes data in table format
D. None of the above

Shw me The Right Answer

Answer . A 

Q.117 What is the purpose of the file() function in R?

A. To delete files
B. To create a connection to a file for reading or writing
C. To list files
D. To copy files

Shw me The Right Answer

Answer . B 

Q.118 Which function in R is used to write data frames to a CSV file?

A. write.csv()
B. export.csv()
C. save.csv()
D. output.csv()

Shw me The Right Answer

Answer . A 

Q.119 What function is used to read CSV files into R?

A. read.csv()
B. load.csv()
C. import.csv()
D. fetch.csv()

Shw me The Right Answer

Answer . A 

Q.120 Why might the sd() function return an error when applied to a dataset in R?

A. The dataset contains non-numeric values
B. The dataset is empty
C. Both reasons mentioned
D. None of the above

Shw me The Right Answer

Answer . A 

Q.121 How can parallel processing improve the performance of an R script?

A. By running tasks sequentially
B. By utilizing multiple CPU cores to run tasks simultaneously
C. By reducing the number of computations
D. By increasing the memory usage

Shw me The Right Answer

Answer . B 

Q.122 What could be a reason for an R script running slower than expected despite being optimized?

A. Hardware limitations
B. Incorrect code logic
C. Insufficient memory
D. All of these factors

Shw me The Right Answer

Answer . A 

Q.123 Which function helps in pre-allocating memory for a vector to improve performance in R?

A. preallocate()
B. vector()
C. alloc()
D. initialize()

Shw me The Right Answer

Answer . B 

Q.124 What is a common method to improve the performance of a loop in R?

A. Use nested loops
B. Use vectorized operations
C. Increase the loop iterations
D. Add more comments

Shw me The Right Answer

Answer . B 

Q.125 Which function in R can be used to measure the execution time of a code block?

A. system.time()
B. exec.time()
C. time()
D. measure.time()

Shw me The Right Answer

Answer . A 

Q.126 What is the primary goal of performance tuning in R?

A. To reduce code readability
B. To make code run faster and more efficiently
C. To increase the complexity of the code
D. To add more features to the code

Shw me The Right Answer

Answer . B 

Q.127 How can you troubleshoot an error in an R Markdown document where code runs in R but not when knitted?

A. Check for environment differences
B. Check for missing library calls
C. Check for chunk options
D. Reinstall R Markdown

Shw me The Right Answer

Answer . B 

Q.128 What could be a reason for an R Markdown document failing to knit properly?

A. Incorrect file path
B. Syntax errors in code chunks
C. Missing package dependencies
D. Insufficient memory

Shw me The Right Answer

Answer . B 

Q.129 How can you include a plot generated in R within an R Markdown document?

A. Create the plot in a code chunk
B. Save the plot as an image and embed it
C. Generate the plot externally
D. Embed the plot URL

Shw me The Right Answer

Answer . A 

Q.130 How do you start a code chunk in an R Markdown document?

A.  {r}
B. 
r
C.  {r}
D.  r {

Shw me The Right Answer

Answer . A 

Q.131 What is a code chunk in R Markdown?

A. A section of code written in R language
B. A section of Markdown syntax
C. A combination of R and Markdown syntax
D. A section of comments only

Shw me The Right Answer

Answer . C 

Q.132 What function is used to render an R Markdown document to HTML?

A. render()
B. convert()
C. compile()
D. output()

Shw me The Right Answer

Answer . A 

Q.133 Which file extension is used for R Markdown files?

A. .Rmd
B. .Rmarkdown
C. .md
D. .R

Shw me The Right Answer

Answer . A 

Q.134 What is the primary purpose of R Markdown?

A. Data visualization
B. Web development
C. Reproducible reporting
D. Database management

Shw me The Right Answer

Answer . C 

Q.135 How can you inspect the structure of an S4 object to understand its slots and their values?

A. str(object)
B. slotNames(object)
C. getSlots(object)
D. show(object)

Shw me The Right Answer

Answer . B 

Q.136 If an S3 method is not dispatching correctly, what is a common issue to check?

A. Incorrect class name
B. Method not defined with setMethod
C. Method not registered
D. Function name mismatch

Shw me The Right Answer

Answer . A 

Q.137 How can you define a method for a generic function show for an S4 class “Person” in R?

A. setGeneric(“show”, function(x) standardGeneric(“show”))
B. setMethod(“show”, “Person”, function(object) { … })
C. show <- function(object) { … }
D. generic(“show”, “Person”, function(object) { … })

Shw me The Right Answer

Answer . B 

Q.138 How do you create an object of a new S4 class named “Person” with a slot “name” in R?

A. new(“Person”, name = “John”)
B. create(“Person”, name = “John”)
C. Person$new(name = “John”)
D. setClass(“Person”, name = “John”)

Shw me The Right Answer

Answer . A 

Q.139 How does method dispatch work in the S4 object system in R?

A. By function naming convention
B. By matching the method name to the class
C. By explicit method registration with setMethod()
D. By object structure analysis

Shw me The Right Answer

Answer . C 

Q.140 What is the purpose of the setClass() function in the S4 object system in R?

A. To create a new S3 class
B. To create a new S4 class
C. To define a new generic function
D. To set a class for an object

Shw me The Right Answer

Answer . B 

Q.141 Which function is used to define a new S3 generic function in R?

A. setGeneric()
B. UseMethod()
C. setMethod()
D. createGeneric()

Shw me The Right Answer

Answer . B 

Q.142 What is the primary difference between S3 and S4 object systems in R?

A. S3 is more formal than S4
B. S3 uses formal class definitions, S4 does not
C. S4 uses formal class definitions, S3 does not
D. There is no difference

Shw me The Right Answer

Answer . C 

Q.143 How can you handle time zone conversions in R?

A. Use the tz argument in functions like as.POSIXct()
B. Use the Sys.timezone() function
C. Use the convert.tz() function
D. Change system time zone settings

Shw me The Right Answer

Answer . A 

Q.144 If as.Date(“31/12/2021”) returns an NA, what is a likely cause?

A. Incorrect date format
B. Non-existent date
C. Year out of range
D. Function does not support date conversion

Shw me The Right Answer

Answer . A 

Q.145 How can you extract the month from a date object in R?

A. month()
B. extractMonth()
C. months()
D. getMonth()

Shw me The Right Answer

Answer . C 

Q.146 How do you create a sequence of dates from January 1, 2021, to January 10, 2021, in R?

A. seq(as.Date(“2021-01-01”), as.Date(“2021-01-10”), by = “day”)
B. sequence(“2021-01-01”, “2021-01-10”)
C. dates(“2021-01-01”, “2021-01-10”)
D. range(as.Date(“2021-01-01”), as.Date(“2021-01-10”))

Shw me The Right Answer

Answer . A 

Q.147 What is the primary difference between POSIXct and POSIXlt date-time classes in R?

A. POSIXct stores dates as strings, POSIXlt as lists
B. POSIXct stores dates as integers, POSIXlt as lists
C. POSIXct stores dates in UTC, POSIXlt in local time
D. There is no difference

Shw me The Right Answer

Answer . B 

Q.148 How can you convert a character string to a date object in R?

A. as.Date()
B. to.Date()
C. convert.Date()
D. stringToDate()

Shw me The Right Answer

Answer . A 

Q.149 What is the class of objects created by the Sys.Date() function in R?

A. Date
B. POSIXct
C. POSIXlt
D. datetime

Shw me The Right Answer

Answer . A 

Q.150 How can you profile the performance of an R script to identify bottlenecks?

A. Use the summary() function
B. Use the lm() function
C. Use the profvis() package
D. Use the plot() function

Shw me The Right Answer

Answer . C 

You may also like...

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments