0% found this document useful (0 votes)
13 views16 pages

Question BANK - R Programming

The document is a question bank for the II Semester BCA SEP 2025, covering various topics related to R programming. It includes definitions, explanations, and examples for key concepts such as CRAN, data types, data structures, and operators in R. The document is structured into sections with 2-mark and 4- and 8-mark questions to aid in understanding and assessment of R programming knowledge.

Uploaded by

Foxfire Gaming
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views16 pages

Question BANK - R Programming

The document is a question bank for the II Semester BCA SEP 2025, covering various topics related to R programming. It includes definitions, explanations, and examples for key concepts such as CRAN, data types, data structures, and operators in R. The document is structured into sections with 2-mark and 4- and 8-mark questions to aid in understanding and assessment of R programming knowledge.

Uploaded by

Foxfire Gaming
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

II Semester BCA SEP Question bank- 2025

UNIT I

2 Mark Questions

1. Define CRAN.

CRAN (Comprehensive R Archive Network)


Definition:
CRAN is the main repository for R packages. It is a network of servers that store up-to-date
versions of code and documentation for R packages contributed by users around the world.
Key Features:
 Contains thousands of R packages.
 Validates and checks packages before publishing.
 Used via functions like install.packages() and update.packages().

2. What is R Programming?

R is a programming language and software environment used for statistical computing, data
analysis, and graphics. It is open-source, supports a wide range of statistical techniques, and
provides powerful tools for data visualization and manipulation.

R is widely used in:


 Data Science
 Machine Learning
 Academic Research
 Bioinformatics
 Finance and Risk Modelling

3. What is data visualization?

Data visualization is the graphical representation of data using charts, graphs, and maps. It
helps to understand trends, patterns, and insights in data more easily by presenting complex
information in a visual and intuitive way.

4. What are the Datatypes available in R?


Data types define the kind of data a variable can hold in a programming language. In R, data
types specify whether the data is numeric, text, logical (TRUE/FALSE), or another form. They
help the program understand how to store and process the values efficiently.

R has the following basic data types:

1. Numeric – Numbers with decimals (e.g., 3.14, 10.5)


2. Integer – Whole numbers (e.g., 1L, 25L)
3. Character – Text or string values (e.g., "Hello")
4. Logical – Boolean values (TRUE or FALSE)
5. Complex – Complex numbers (e.g., 3 + 2i)
6. Raw – Raw bytes, mainly for low-level operations
These types are used to build more complex data structures like vectors, matrices, and data
frames.

5. Define factor.

A factor is a data structure in R used to represent categorical data. It stores vector


data with a fixed set of unique values called levels. Factors are especially useful in
statistical modelling where categorical variables (like gender, status, etc.) need to be
treated differently from continuous data.

Example:

status <- factor(c("single", "married", "single", "divorced"))

levels(status) # Shows: "divorced" "married" "single"

6. What is dataframe?

A data frame is a data structure in R used to store data in tabular form (rows and columns),
similar to a spreadsheet or SQL table. Each column can contain different data types (e.g.,
numeric, character, logical), but all columns must have the same number of rows.

Example:

df <- data.frame(
Name = c("Alice", "Bob"),
Age = c(25, 30),
Passed = c(TRUE, FALSE)
)

7. Define paste() .
The paste() function in R is used to combine multiple strings or variables into a single string.
It automatically inserts a space between the elements by default, but you can change the
separator using the sep argument.

Example:

paste("Hello", "World") # Output: "Hello World"


paste("R", "Programming", sep = "-") # Output: "R-Programming"

It is useful for creating labels, messages, or dynamic text.

8. What is difference between array and matrix?

A matrix in R is a 2-dimensional data structure consisting of elements arranged in rows and


columns. All elements in a matrix must be of the same data type (e.g., all numeric or all
character).

An array is a more general data structure in R that can have two or more dimensions (e.g.,
2D, 3D, or higher). Like matrices, all elements in an array must be of the same data type.

Feature Matrix Array

Exactly 2 dimensions (rows


Dimensions Can have 2 or more dimensions
and columns)

A special case of an array General multi-dimensional


Structure
limited to 2D structure

For tabular data like For higher-dimensional data, like


Use cases
spreadsheets 3D images or time-series data

Created using matrix()


Creation Created using array() function
function

matrix(1:6, nrow=2,
Example array(1:8, dim = c(2, 2, 2))
ncol=3)

Access elements by row Access elements by indices across


Access
and column indices all dimensions

9. Explain vector.

A vector in R is the simplest and most basic data structure. It is a one-dimensional collection
of elements that are all of the same data type (such as numeric, character, or logical).
Vectors are used to store sequences of data.
Example:

numbers <- c(1, 2, 3, 4, 5) # Numeric vector


names <- c("Alice", "Bob", "Eve") # Character vector

10. What is Coercion?

Coercion in R is the process of automatically converting one data type to another when
combining different types in a vector or expression. R follows a hierarchy of data types and
coerces to the most flexible type to avoid errors.

Example:
vec <- c(1, "apple", TRUE)
# Numeric 1 and logical TRUE are coerced to character, so vec becomes a character vector

11. What is Plot?

A plot in R is a graphical representation of data that helps visualize relationships, patterns, or


trends. It can be a scatterplot, line graph, bar chart, histogram, or other types of charts used
to make data easier to understand.

Example:

plot(1:5, c(2,4,6,8,10)) # Simple scatter plot of points

4- and 8-mark questions

1. What are the ways to assign variables in R?

Ways to Assign Variables in R (Detailed Explanation):

In R, assigning values to variables is fundamental for storing and manipulating data. There
are three main ways to assign values to variables:

1. Using the Leftward Assignment Operator <-

This is the most common and recommended method in R. It assigns the value on the right to
the variable on the left.

Example:

x <- 5

name <- "Alice"

 Preferred by the R community for clarity.


 Allows chaining of assignments, e.g., a <- b <- 10.

2. Using the Equal Sign =


The equal sign can also be used to assign values to variables, similar to many other
programming languages.
Example:
x=5
name = "Alice"

 Works mostly the same as <- but can sometimes cause confusion inside function calls,
where = is used to assign function arguments.
 Less preferred for variable assignment outside functions.

3. Using the Rightward Assignment Operator ->

This operator assigns the value on the left to the variable on the right. It is less commonly
used but sometimes helpful in pipelines or when reading code bottom-to-top.

Example:

5 -> x

"Alice" -> name

Additional Notes:

 Variables in R are case sensitive, so x and X are different variables.

 Variable names should start with a letter and can contain letters, numbers, dots, and
underscores.

 It is good practice to use meaningful variable names for readability.

Operator Direction of Assignment Usage Frequency Example

<- Right to left (value → variable) Most common x <- 10

= Right to left Common but less preferred x = 10

-> Left to right (value → variable) Rare 10 -> x

3. Explain the Datatypes available in R?

In R, data types define the kind of data a variable can hold. R supports several basic data
types that are fundamental for data processing and analysis.

1. Numeric

 Represents real numbers (both integers and decimals).

 Default data type for numbers with decimals.

 Example: 3.14, 10, -5.6


2. Integer

 Represents whole numbers without decimals.

 Explicitly declared by adding an L suffix.

 Example: 5L, 100L

 Without L, numbers are treated as numeric (double) by default.

3. Character

 Represents text or string data.

 Stored as sequences of characters enclosed in quotes.

 Example: "Hello", "R Programming"

4. Logical

 Represents Boolean values: TRUE or FALSE.

 Often used in conditions and control flow.

 Example: TRUE, FALSE

5. Complex

 Represents complex numbers with real and imaginary parts.

 Example: 3 + 2i, 5 - 1i

6. Raw

 Represents raw bytes, usually for low-level operations or binary data.

 Less commonly used in everyday data analysis.

Importance of Data Types in R:

 Data types determine how data is stored and processed.

 They ensure correct operations (e.g., math on numeric types, text manipulation on
characters).

 Coercion may happen if different data types are combined.

Data Type Description Example

Numeric Real numbers (default) 2.5, 100

Integer Whole numbers 10L, -3L

Character Text strings "Data", "R"

Logical Boolean values TRUE, FALSE

Complex Complex numbers 2 + 3i

Raw Raw bytes as.raw(0x65)


Data Type Description Example

example in R that creates variables for all basic data types:

# Numeric

num <- 3.14

# Integer

int <- 5L

# Character

char <- "Hello"

# Logical

logi <- TRUE

# Complex

comp <- 2 + 3i

# Raw

raw_val <- charToRaw("R")

4. Write about Data structures in R.

In R, data structures organize and store data in different ways to enable efficient data
analysis and manipulation. They define how data is arranged and accessed. R provides
several fundamental data structures:

1. Vector

 The simplest data structure, a one-dimensional sequence of elements.

 All elements must be of the same data type (numeric, character, logical, etc.).

 Example: c(1, 2, 3) or c("a", "b", "c").

2. Matrix

 A two-dimensional rectangular data structure with rows and columns.


 All elements must be of the same data type.

 Created using the matrix() function.

 Example: matrix(1:6, nrow=2, ncol=3).

3. Array

 A generalization of matrices to more than two dimensions.

 Elements must be of the same data type.

 Created using the array() function.

 Example: array(1:8, dim=c(2, 2, 2)).

4. List

 A one-dimensional collection of elements which can be of different data types and


structures.

 Useful for storing mixed types of data in one object.

 Created using the list() function.

 Example: list(name="Alice", age=25, scores=c(90, 85)).

5. Data Frame

 A two-dimensional, tabular data structure similar to a spreadsheet or database table.

 Columns can contain different data types (numeric, character, factor, etc.), but each
column must be of a single type.

 Created using data.frame() function.

 Most commonly used structure for data analysis.

 Example:

 data.frame(Name=c("Alice", "Bob"), Age=c(25, 30), Passed=c(TRUE, FALSE))

6. Factor:

A factor in R is a special data structure used to represent categorical variables. It stores


data as a set of levels that define the possible categories. Factors can be nominal (no
order) or ordinal (ordered), and they are important for statistical modeling and analysis
of categorical-data.

Example:

# Vector (1D, homogeneous)

vec <- c(1, 2, 3, 4)


# Matrix (2D, homogeneous)

mat <- matrix(1:6, nrow=2, ncol=3)

# Array (3D, homogeneous)

arr <- array(1:8, dim = c(2, 2, 2))

# List (1D, heterogeneous)

lst <- list(name="Alice", age=25, scores=c(90, 85))

# Data Frame (2D, heterogeneous columns)

df <- data.frame(Name=c("Bob", "Carol"), Age=c(30, 28), Passed=c(TRUE, FALSE))

colors <- factor(c("red", "blue", "red", "green"))

# Print all

print(vec)

print(mat)

print(arr)

print(lst)

print(df)

5. How will you get input from user in R?

In R, you can get input from the user during program execution using the readline() function.
This function reads a line of text from the console as a string.

1. Using readline() Function


 Syntax:
input <- readline(prompt = "Enter your input: ")

 The prompt argument displays a message asking the user to enter data.
 The input is captured as a character string.

2. Converting Input to Other Data Types

Since readline() returns a string, you often need to convert it to the required data type, such
as numeric or integer.

 Convert to numeric:
age <- as.numeric(readline("Enter your age: "))

 Convert to integer:

count <- as.integer(readline("Enter count: "))

3. Example: Reading and Using User Input:

name <- readline("Enter your name: ")

age <- as.numeric(readline("Enter your age: "))

cat("Hello", name, "! You are", age, "years old.\n")

 Input is always read as a string initially.


 Conversion functions like as.numeric(), as.integer(), or as.logical() help convert input to
appropriate types.
 If conversion fails (e.g., entering non-numeric data when expecting a number), R returns
NA with a warning.

6. Differentiate Vector and List

Feature Vector List

Homogeneous (all elements must be the Heterogeneous (elements can be of


Data Type
same type, e.g., all numeric or all character) different types and structures)

Dimensions One-dimensional One-dimensional

Creation Created using c() function Created using list() function

Store simple sequences of data like Store complex or mixed data like numbers,
Use Case
numbers or characters strings, vectors, or even other lists

lst <- list(name="Alice", age=25,


Example vec <- c(1, 2, 3, 4)
scores=c(90, 85))

Access elements by single index (e.g., Access elements by index or name (e.g.,
Access
vec[1]) lst[[1]] or lst$name)

Flexibility Less flexible due to uniform type More flexible, supports mixed data types

 Vectors are simple, homogeneous collections of elements.


 Lists are flexible, can hold mixed types and complex objects.

Vector Example:

# Numeric vector with homogeneous elements


vec <- c(10, 20, 30, 40)

print(vec)

# Accessing the first element

print(vec[1]) # Output: 10

List Example:

# List with heterogeneous elements

lst <- list(name = "Alice", age = 25, scores = c(90, 85, 88))

print(lst)

# Accessing elements by name and index

print(lst$name) # Output: "Alice"

print(lst[[2]]) # Output: 25 (age)

print(lst$scores) # Output: 90 85 88

7. Explain about the different types of operators in R.

Operators in R are special symbols or keywords used to perform operations on variables and
values. They help in arithmetic calculations, comparisons, logical tests, and more.
1. Arithmetic Operators
Used to perform mathematical calculations.

Operator Description Example

+ Addition 5+3=8

- Subtraction 5-3=2

* Multiplication 5 * 3 = 15

/ Division 6/3=2

^ or ** Exponentiation 2^3=8

%% Modulus (remainder) 5 %% 2 = 1

%/% Integer division 5 %/% 2 = 2

2. Relational (Comparison) Operators


Used to compare values and return logical results (TRUE or FALSE).

Operator Description Example

== Equal to 5 == 5 → TRUE
Operator Description Example

!= Not equal to 5 != 3 → TRUE

< Less than 3 < 5 → TRUE

> Greater than 5 > 3 → TRUE

<= Less than or equal to 3 <= 3 → TRUE

>= Greater than or equal to 5 >= 4 → TRUE

3. Logical Operators
Used to combine or negate logical conditions.

Operator Description Example

& Logical AND (TRUE & FALSE) → FALSE

&& Logical AND (single element) (TRUE && FALSE) → FALSE

! Logical NOT !TRUE → FALSE

4. Assignment Operators
Used to assign values to variables.

Operator Description Example

<- Assign value to variable x <- 5

-> Assign value (right to left) 5 -> x

= Assign value x=5

5. Miscellaneous Operators

Operator Description Example

1:5 generates
: Sequence generation
1,2,3,4,5

3 %in% c(1,2,3,4)
%in% Matches elements in vectors
→ TRUE

Extract elements by name from


$ df$Age
lists or data frames

@ Access slots in S4 objects Used in advanced


OOP
Example:

# Arithmetic Operators

a <- 10

b <- 3

sum <- a + b # Addition: 13

diff <- a - b # Subtraction: 7

prod <- a * b # Multiplication: 30

quot <- a / b # Division: 3.333...

power <- a ^ b # Exponentiation: 1000

mod <- a %% b # Modulus: 1

int_div <- a %/% b # Integer division: 3

# Relational Operators

is_equal <- (a == b) # FALSE

not_equal <- (a != b) # TRUE

less_than <- (a < b) # FALSE

greater_than <- (a > b) # TRUE

less_equal <- (a <= 10) # TRUE

greater_equal <- (a >= 20) # FALSE

# Logical Operators

logical_and <- (a > 5 & b < 5) # TRUE

logical_or <- (a < 5 | b < 5) # TRUE

logical_not <- !(a == b) # TRUE

# Assignment Operators

x <- 100

200 -> y

z = 300
# Miscellaneous Operators

seq <- 1:5 # Sequence from 1 to 5

vec <- c(1, 3, 5, 7, 9)

in_check <- 3 %in% vec # TRUE

# Print results

print(paste("Sum:", sum))

print(paste("Is equal:", is_equal))

print(paste("Logical AND:", logical_and))

print(paste("Sequence:", paste(seq, collapse = ", ")))

print(paste("Is 3 in vector:", in_check))

UNIT II

2 Mark Questions

1. Write the syntax of else if in R

2. What is nested if statement?


3. State the difference between repeat and break
4. What is standalone statement?
5. State the use of warning () function
6. What is file? Why you need file in programming?
7. What do you mean by .csv files?
8. What is timing?
9. Define visibility
10. What is namespace?

4- and 8-mark questions

1. What are the different types of decision-making statements?


2. Explain the looping statements in R
3. Explain with an example how will you call a user defined function in R?
4. Write neatly about exception handling with example
5. How will you create a file? Give example
6. Explain file operations in detail
7. Explain visibility and timing in R?

UNIT III
2 Mark Questions

1. Define box plot


2. What are the uses of Histograms?
3. What is Statistics?
4. Define Probability
5. What is random variable?
6. State the R function used to fined mean.
7. Explain cumulative sum
8. What is the difference between integral and calculus?
9. Find the mean and mode of the following data: 2, 3, 5, 6, 10, 6, 12, 6, 3, 4.
10. State any two applications of Bernoulli Distribution.
11. What is qbern() function?

4 and 8 mark questions

1. Explain in detail about the basic visualization techniques.


2. Write about statistics functions available in R.
3. State and explain variance with programming example
4. Explain Probability Mass Functions
5. Explain Probability Density Functions
6. Explain R functions in Bernoulli distribution
7. Define i)dpois ii)ppois iii)qpois iv)rpois
8. Explain Binomial Distribution
9. What is normal distribution

UNIT IV

2 Mark Questions

1. What is Statistical testing?


2. Expand ANOVA
3. What is hypothesis?
4. Define power
5. Differentiate one tailed and two tailed hypothesis
6. State any one assumption of ANOVA?
7. Expand MANOVA
8. Write any two statistics formula.

4 and 8 mark questions

1. State and explain the types of hypothesis


2. Differentiate type 1 error and type 2 error.
3. Explain in detail about ANOVA
4. Explain aov() in detail
5. What is normal distribution?
6. What are the components of hypothesis testing
7. Explain t.test() with suitable example
8. Explain chisqtest()

UNIT V

2 Mark Questions

1. What is linear regression?


2. What is negative linear relationship?
3. Give one example for multiple linear regression.
4. State the different ways to declare colors
5. Define plotly
6. Define multiple linear regression

4 and 8 mark questions

1. Explain 3D scatter plot


2. How will you define colors
3. How to add text in plots?
4. What are the different packages available in R for advanced graphics
5. Discuss point and click coordination
6. How will you customize the traditional plots?

You might also like