Font size
WorksheetsRP unit-1
Total questions: 18
Worksheet time: 9mins
Define R programming language and what is meant by data structures in R. [R] – 1 Marks
R is a statistical programming environment; data structures are organized ways to store and access data such as vectors, matrices, lists, and data frames.
R is only a database query tool; data structures are SQL tables and views.
R is a markup language; data structures are HTML elements like div and span.
R is a spreadsheet application; data structures are worksheets and cells.
Explain the role of vectors as the basic data structure in R. [U] – 2 Marks
Vectors are the fundamental one-dimensional, homogeneous containers in R; most operations are vectorized and act element-wise.
Vectors are secondary structures used only for plotting; matrices are the only fundamental objects.
Vectors are heterogeneous by default, mixing types freely without coercion.
Vectors exist only for character data; numeric data uses lists.
Apply the concept of vectors to create and manipulate a numeric dataset representing student marks in R. Which option correctly creates a marks vector and returns its average? [AP] – 3 Marks
marks <- c(78, 85, 91, 66); mean(marks)
marks <- list(78, 85, 91, 66); sum(marks)/length(marks) produces an error
marks <- c("78", "85", "91", "66"); mean(marks) returns the same numbers
marks <- matrix(c(78,85,91,66)); mean(list(marks))
What is vector declaration in R and which syntax is correct? [R] – 1 Marks
Using the combine function: x <- c(1, 2, 3)
Using assignment to a scalar: x = (1, 2, 3)
Using array literal: x := [1,2,3]
Using list constructor: x <- list(1,2,3) to make a numeric vector
Which of the following are valid ways to declare or generate vectors in R? Select all that apply. [U] – 2 Marks
c(1,2,3)
1:10
seq(0, 1, by = 0.25)
rep(TRUE, 4)
array(1:4, dim = c(2,2))
Apply vector declaration techniques to create numeric, character, and logical vectors and display their properties. Which option correctly matches type and a property check? [AP] – 3 Marks
class(c(1,2,3)) returns "numeric", class(c("a","b")) returns "character", class(c(TRUE,FALSE)) returns "logical"
length(c(1,2,3)) returns "numeric", length(c("a","b")) returns "character", length(c(TRUE,FALSE)) returns "logical"
typeof(c(1,2,3)) returns "list", typeof(c("a","b")) returns "complex", typeof(c(TRUE,FALSE)) returns "integer"
class(c(1,2,3)) returns "integer" only when mixed types are present
List any four common vector operations in R. Which set best represents common operations? [R] – 1 Marks
Indexing, concatenation, arithmetic, logical comparison
Window docking, file I/O, sockets, threading
Class inheritance, polymorphism, method overriding, encapsulation
Network requests, JSON parsing, DOM manipulation, CSS styling
Explain how arithmetic and logical operations are performed on vectors in R. [U] – 2 Marks
Operations are vectorized and apply element-wise; shorter vectors may be recycled.
Operations require explicit loops over indices for arithmetic; logical operators cannot be applied element-wise.
Arithmetic is only defined for scalars; vectors must be converted to lists first.
Logical operations work only on character vectors.
Apply common vector operations to a real-world task: calculating total sales, average profit, and identifying high values. Which R expression correctly finds the indices of sales values above 100? [AP] – 3 Marks
which(sales > 100)
match(100, sales)
subset(sales, 100)
sum(sales == 100)
What is a vector in R, and which are valid types? Mention any two types. [R] – 1 Marks
An atomic, ordered collection of elements of the same type; valid types include numeric, character, logical, integer, and complex.
A heterogeneous container that mixes different types freely by default; valid types include table and data frame.
A two-dimensional grid; valid types include row and column.
A pointer to external objects; valid types include file and connection.
Explain how vectors differ from scalars in R programming. [U] – 2 Marks
A scalar in R is simply a vector of length 1; operations treat it as a vector.
Scalars are a distinct built-in type separate from vectors.
Scalars cannot participate in arithmetic with vectors.
Vectors are only lists, while scalars are numbers.
Apply scalar and vector concepts to perform arithmetic on a single value and a vector in R. What is the result of 5 + c(1, 2, 3)? [AP] – 3 Marks
c(6, 7, 8)
c(5, 5, 5)
c(1, 2, 3, 5)
An error because 5 is not a vector
List any four built-in help functions available in R. Which option lists help features? [R] – 1 Marks
help(), ?, example(), help.search()
open(), read(), write(), close()
install.packages(), library(), detach(), remove.packages()
ls(), rm(), get(), assign()
Explain how help functions assist programmers in understanding vector operations in R. [U] – 2 Marks
They provide documentation pages, usage, arguments, and examples for functions like c() and length(), making behavior clear.
They automatically rewrite code to the most efficient vectorized form.
They compile R code to machine language for faster vector operations.
They create plots by default for any vector
Apply help functions to explore syntax, usage, and examples of the c() and length() functions. Which commands correctly show documentation and run examples? [AP] – 3 Marks
?c and example(length)
help.search("c()") and ?length runs examples
apropos("c") automatically executes c() on a sample
?length and example(c) are invalid
Define vector recycling in R. [R] – 1 Marks
When operating on vectors of unequal length, the shorter vector’s elements are repeated in order to match the longer vector’s length.
A memory optimization that deletes unused vector elements.
A process that converts vectors into lists for reuse.
A garbage-collection technique for clearing temporary vectors.
Explain the recycling rule followed by R during vector operations of unequal length. [U] – 2 Marks
The shorter vector is recycled; if the longer length is not a multiple of the shorter, R issues a warning.
R silently truncates the longer vector to the shorter length.
R throws an error and stops computation for any unequal lengths.
R pads with NA regardless of lengths.
Apply the recycling rule to perform arithmetic on vectors of different lengths and interpret the result. What is c(1, 2, 3, 4) + c(10, 20)? [AP] – 3 Marks
c(11, 22, 13, 24) with a recycling warning
c(11, 22) only, because extra elements are ignored
c(NA, NA, NA, NA) because lengths differ
An error and no result
