Docsity

R Programming & Statistical Computing Exam 2026: Comprehensive University-Level Practice E, Exams of Nursing

Toggle sidebar
bg1
R Programming & Statistical Computing Exam 2026: Comprehensive
University-Level Practice Examination — R Syntax, Data Structures,
Data Manipulation, Statistical Analysis, Visualization, Probability,
Regression, Hypothesis Testing & Programming — 190 Multiple-
Choice Questions with Answers & Detailed Rationales
SECTION 1: R BASICS AND DATA TYPES (Questions 1-25)
Question 1
What is the primary purpose of the assignment operator <- in R?
A. To compare two values for equality
B. To assign a value to a variable
C. To create a comment in code
D. To concatenate strings
Correct Answer: B
Explanation: The <- operator assigns values to variables in R, though = also works. It's the
idiomatic assignment operator in R programming.
Question 2
Which function is used to determine the data type of an object in R?
A. type()
B. typeof()
C. datatype()
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28

Partial preview of the text

Download R Programming & Statistical Computing Exam 2026: Comprehensive University-Level Practice E and more Exams Nursing in PDF only on Docsity!

R Programming & Statistical Computing Exam 2026: Comprehensive University-Level Practice Examination — R Syntax, Data Structures, Data Manipulation, Statistical Analysis, Visualization, Probability, Regression, Hypothesis Testing & Programming — 190 Multiple- Choice Questions with Answers & Detailed Rationales SECTION 1: R BASICS AND DATA TYPES (Questions 1-25) Question 1 What is the primary purpose of the assignment operator <- in R? A. To compare two values for equality B. To assign a value to a variable C. To create a comment in code D. To concatenate strings Correct Answer : B Explanation: The <- operator assigns values to variables in R, though = also works. It's the idiomatic assignment operator in R programming. Question 2 Which function is used to determine the data type of an object in R? A. type() B. typeof() C. datatype()

D. classonly() Correct Answer : B Explanation: typeof() returns the internal data type, while class() returns the object's class attribute. Both are useful for different purposes. Question 3 What will be the output of length(c(1, 2, NA, 4)) in R? A. 3 B. 4 C. NA D. Error Correct Answer : B Explanation: The length() function counts all elements including NA values. It returns 4 because NA is still an element in the vector. Question 4 Which R object can contain elements of different data types? A. Vector B. Matrix C. List

D. Negative answer Correct Answer : A Explanation: NA stands for "Not Available" and represents missing values. It's different from NULL which represents the absence of an object. Question 7 Which function creates a sequence of numbers from 1 to 10 in increments of 2? A. seq(1, 10, 2) B. range(1, 10, 2) C. series(1, 10, 2) D. order(1, 10, 2) Correct Answer : A Explanation: seq() generates sequences with specified parameters: from, to, and by. It produces 1, 3, 5, 7, 9. Question 8 What is the result of paste("Hello", "World", sep="-")? A. "Hello World" B. "Hello-World" C. "HelloWorld"

D. "Hello, World" Correct Answer : B Explanation: The paste() function concatenates strings with the specified separator. The sep="-" argument places a hyphen between elements. Question 9 Which operator performs integer division in R? A. / B. %/% C. %% D. // Correct Answer : B Explanation: %/% performs integer (floor) division, while %% returns the modulus (remainder). For example, 7 %/% 2 returns 3. Question 10 A data analyst needs to check if a value is NULL. Which function should they use? A. is.na() B. is.null() C. is.empty()

D. x[0] Correct Answer : A Explanation: Negative indexing in R excludes elements. x[-1] returns all elements except the first one, effectively removing it. Question 13 In R, what is the purpose of the L suffix in 10L? A. Indicates a long integer B. Indicates a literal integer C. Indicates a logical value D. Indicates a list element Correct Answer : B Explanation: The L suffix explicitly creates an integer type. Without it, 10 would be stored as a double (numeric) type. Question 14 A student writes x <- 5; y <- x > 3. What is the value of y? A. 5 B. 3 C. TRUE

D. FALSE

Correct Answer : C Explanation: The expression x > 3 evaluates to TRUE since 5 is greater than 3. The variable y stores this logical result. Question 15 Which function converts a character string "123" to a numeric value? A. as.numeric("123") B. numeric("123") C. convert("123") D. to.number("123") Correct Answer : A Explanation: as.numeric() coerces character strings to numeric type when possible. It returns 123 as a numeric value. Question 16 What happens when you add a number to a logical vector in R? A. Error occurs B. NA is returned C. Logical values are coerced to numeric

D. List Correct Answer : C Explanation: When combining different types in a vector, R coerces all elements to the most flexible type. Here, everything becomes character. Question 19 Which function returns the number of characters in a string? A. length() B. nchar() C. strlen() D. count() Correct Answer : B Explanation: nchar() counts characters in a string, while length() counts elements in a vector. They serve different purposes. Question 20 A data scientist writes x <- NULL. What is length(x)? A. 0 B. 1 C. NA

D. Error Correct Answer : A Explanation: NULL represents an empty object with length 0. It's different from NA which has length 1 when in a vector. Question 21 What is the result of round(3.567, 2)? A. 3. B. 3. C. 3. D. 4 Correct Answer : B Explanation: round() rounds to specified decimal places. 3.567 rounded to 2 decimals is 3. due to standard rounding rules. Question 22 Which function generates random numbers from a normal distribution? A. runif() B. rnorm() C. rbinom()

D. Both have length 0 Correct Answer : B Explanation: NA represents a missing value and has length 1, while NULL represents the absence of an object and has length 0. Question 25 Which function checks if an object is a matrix? A. is.matrix() B. is.array() C. is.table() D. is.grid() Correct Answer : A Explanation: is.matrix() specifically tests for matrix objects. Matrices are 2-dimensional arrays with special attributes. SECTION 2: DATA STRUCTURES (Questions 26-50) Question 26 How do you access the element in the second row and third column of a matrix m? A. m[2, 3] B. m(2, 3)

C. m{2, 3} D. m[[2, 3]] Correct Answer : A Explanation: Matrix indexing uses square brackets with row and column indices separated by a comma: m[row, column]. Question 27 What is the class of matrix(1:6, nrow=2)? A. Vector B. Array C. Matrix D. Data frame Correct Answer : C Explanation: The matrix() function creates a matrix object. It's a 2-dimensional array with class "matrix" and "array". Question 28 A researcher creates df <- data.frame(x=1:3, y=letters[1:3]). How many columns does df have? A. 1 B. 2

C. 0

D. NA

Correct Answer : A Explanation: nrow() returns the number of rows in a data frame or matrix. For 5 rows, it returns 5. Question 31 A list lst <- list(a=1, b="two", c=TRUE). What is lst$b? A. 1 B. "two" C. TRUE D. NULL Correct Answer : B Explanation: The $ operator accesses list elements by name. lst$b returns the value "two" stored in element b. Question 32 Which function extracts a subset of a data frame based on conditions? A. subset() B. filter()

C. select() D. extract() Correct Answer : A Explanation: Base R's subset() function filters data frames by conditions. filter() is from dplyr package, not base R. Question 33 What is the result of dim(matrix(1:12, nrow=3, ncol=4))? A. 12 B. 3, 4 C. 4, 3 D. 7 Correct Answer : B Explanation: dim() returns the dimensions as a vector: number of rows first, then columns. Here it's 3, 4. Question 34 How do you add a new column z to an existing data frame df? A. df$z <- values B. add(df, z)

C. matrix() D. convert.matrix() Correct Answer : A Explanation: as.matrix() coerces a data frame to a matrix. All columns must be compatible types or coercion occurs. Question 37 What is the primary difference between a matrix and a data frame? A. Matrices can only hold numeric data B. Data frames can hold different types per column C. Matrices cannot have names D. Data frames cannot be indexed Correct Answer : B Explanation: Data frames can have columns of different types, while matrices require all elements to be the same type. Question 38 A list contains lst <- list(1:3, "a", TRUE). What is length(lst)? A. 3 B. 6

C. 1

D. 5

Correct Answer : A Explanation: length() on a list returns the number of top-level elements. Here there are 3 elements, regardless of their contents. Question 39 Which function creates a factor variable in R? A. factor() B. categorical() C. levels() D. group() Correct Answer : A Explanation: factor() creates categorical variables. It stores values as levels (categories) with integer codes internally. Question 40 What does levels(factor(c("a", "b", "a", "c"))) return? A. "a", "b", "c" B. 1, 2, 3