wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

RP unit-1

Total questions: 18

Worksheet time: 9mins

Name
Class
Date
1.

Define R programming language and what is meant by data structures in R. [R] – 1 Marks

a)

R is a statistical programming environment; data structures are organized ways to store and access data such as vectors, matrices, lists, and data frames.

b)

R is only a database query tool; data structures are SQL tables and views.

c)

R is a markup language; data structures are HTML elements like div and span.

d)

R is a spreadsheet application; data structures are worksheets and cells.

2.

Explain the role of vectors as the basic data structure in R. [U] – 2 Marks

a)

Vectors are the fundamental one-dimensional, homogeneous containers in R; most operations are vectorized and act element-wise.

b)

Vectors are secondary structures used only for plotting; matrices are the only fundamental objects.

c)

Vectors are heterogeneous by default, mixing types freely without coercion.

d)

Vectors exist only for character data; numeric data uses lists.

3.

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

a)

marks <- c(78, 85, 91, 66); mean(marks)

b)

marks <- list(78, 85, 91, 66); sum(marks)/length(marks) produces an error

c)

marks <- c("78", "85", "91", "66"); mean(marks) returns the same numbers

d)

marks <- matrix(c(78,85,91,66)); mean(list(marks))

4.

What is vector declaration in R and which syntax is correct? [R] – 1 Marks

a)

Using the combine function: x <- c(1, 2, 3)

b)

Using assignment to a scalar: x = (1, 2, 3)

c)

Using array literal: x := [1,2,3]

d)

Using list constructor: x <- list(1,2,3) to make a numeric vector

5.

Which of the following are valid ways to declare or generate vectors in R? Select all that apply. [U] – 2 Marks

a)

c(1,2,3)

b)

1:10

c)

seq(0, 1, by = 0.25)

d)

rep(TRUE, 4)

e)

array(1:4, dim = c(2,2))

6.

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

a)

class(c(1,2,3)) returns "numeric", class(c("a","b")) returns "character", class(c(TRUE,FALSE)) returns "logical"

b)

length(c(1,2,3)) returns "numeric", length(c("a","b")) returns "character", length(c(TRUE,FALSE)) returns "logical"

c)

typeof(c(1,2,3)) returns "list", typeof(c("a","b")) returns "complex", typeof(c(TRUE,FALSE)) returns "integer"

d)

class(c(1,2,3)) returns "integer" only when mixed types are present

7.

List any four common vector operations in R. Which set best represents common operations? [R] – 1 Marks

a)

Indexing, concatenation, arithmetic, logical comparison

b)

Window docking, file I/O, sockets, threading

c)

Class inheritance, polymorphism, method overriding, encapsulation

d)

Network requests, JSON parsing, DOM manipulation, CSS styling

8.

Explain how arithmetic and logical operations are performed on vectors in R. [U] – 2 Marks

a)

Operations are vectorized and apply element-wise; shorter vectors may be recycled.

b)

Operations require explicit loops over indices for arithmetic; logical operators cannot be applied element-wise.

c)

Arithmetic is only defined for scalars; vectors must be converted to lists first.

d)

Logical operations work only on character vectors.

9.

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

a)

which(sales > 100)

b)

match(100, sales)

c)

subset(sales, 100)

d)

sum(sales == 100)

10.

What is a vector in R, and which are valid types? Mention any two types. [R] – 1 Marks

a)

An atomic, ordered collection of elements of the same type; valid types include numeric, character, logical, integer, and complex.

b)

A heterogeneous container that mixes different types freely by default; valid types include table and data frame.

c)

A two-dimensional grid; valid types include row and column.

d)

A pointer to external objects; valid types include file and connection.

11.

Explain how vectors differ from scalars in R programming. [U] – 2 Marks

a)

A scalar in R is simply a vector of length 1; operations treat it as a vector.

b)

Scalars are a distinct built-in type separate from vectors.

c)

Scalars cannot participate in arithmetic with vectors.

d)

Vectors are only lists, while scalars are numbers.

12.

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

a)

c(6, 7, 8)

b)

c(5, 5, 5)

c)

c(1, 2, 3, 5)

d)

An error because 5 is not a vector

13.

List any four built-in help functions available in R. Which option lists help features? [R] – 1 Marks

a)

help(), ?, example(), help.search()

b)

open(), read(), write(), close()

c)

install.packages(), library(), detach(), remove.packages()

d)

ls(), rm(), get(), assign()

14.

Explain how help functions assist programmers in understanding vector operations in R. [U] – 2 Marks

a)

They provide documentation pages, usage, arguments, and examples for functions like c() and length(), making behavior clear.

b)

They automatically rewrite code to the most efficient vectorized form.

c)

They compile R code to machine language for faster vector operations.

d)

They create plots by default for any vector

15.

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

a)

?c and example(length)

b)

help.search("c()") and ?length runs examples

c)

apropos("c") automatically executes c() on a sample

d)

?length and example(c) are invalid

16.

Define vector recycling in R. [R] – 1 Marks

a)

When operating on vectors of unequal length, the shorter vector’s elements are repeated in order to match the longer vector’s length.

b)

A memory optimization that deletes unused vector elements.

c)

A process that converts vectors into lists for reuse.

d)

A garbage-collection technique for clearing temporary vectors.

17.

Explain the recycling rule followed by R during vector operations of unequal length. [U] – 2 Marks

a)

The shorter vector is recycled; if the longer length is not a multiple of the shorter, R issues a warning.

b)

R silently truncates the longer vector to the shorter length.

c)

R throws an error and stops computation for any unequal lengths.

d)

R pads with NA regardless of lengths.

18.

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

a)

c(11, 22, 13, 24) with a recycling warning

b)

c(11, 22) only, because extra elements are ignored

c)

c(NA, NA, NA, NA) because lengths differ

d)

An error and no result