Business Forecasting - Lab Manual
Business Forecasting - Lab Manual
LAB MANUAL
SEMESTER- III
SUBJECT TITLE
Business Forecasting
SUBJECT CODE
V20PBBA03
Basic Operations in R
Basic Commands:
## [1] 8
## [1] 0
## [1] 16
## [1] 1
R Programming Language offers a factorial() a function that can compute the factorial of a
number without writing the whole code for computing factorial.
Algorithm:
Syntax: factorial(x)
Method 1:
print(answer1)
print(answer2)
print(answer3)
Output:
24
print(answer1)
Output:
1 1 2 6 24
The Fibonacci sequence is a series of numbers in which each number (known as a Fibonacci
number) is the sum of the two preceding ones. The sequence starts with 0 and 1, and then each
subsequent number is the sum of the two previous numbers. The Fibonacci sequence has many
applications in various fields, including mathematics, computer science, and nature.
To generate the Fibonacci sequence in R Programming Language, we will use a loop. The
sequence is defined as follows:
Steps:
1. Take the input for the number of terms (n) to be generated in the sequence.
2. Use a loop to generate the Fibonacci numbers.
3. Print the numbers in the sequence.
a <- 0
b <- 1
cat("Fibonacci Sequence:")
for (i in 1:n) {
next_num <- a + b
a <- b
b <- next_num
# Example usage
number_of_terms <- 10
print_fibonacci(number_of_terms)
Output:
Fibonacci Sequence:0 1 1 2 3 5 8 13 21 34
A pie chart is a circular statistical graphic, which is divided into slices to illustrate numerical
proportions. It depicts a special chart that uses “pie slices”, where each sector shows the relative
sizes of data. A circular chart cuts in the form of radii into segments describing relative
frequencies or magnitude also known as a circle graph.
R Programming Language uses the function pie() to create pie charts. It takes positive
numbers as a vector input.
Parameters:
• x: This parameter is a vector that contains the numeric values which are used in the pie
chart.
• labels: This parameter gives the description to the slices in pie chart.
• radius: This parameter is used to indicate the radius of the circle of the pie chart.(value
between -1 and +1).
• main: This parameter is represents title of the pie chart.
• clockwise: This parameter contains the logical value which indicates whether the slices
are drawn clockwise or in anti clockwise direction.
• col: This parameter give colors to the pie in the graph.
pie(geeks, labels)
Output:
Experiment 4. R – Histograms
Parameters:
Creating a simple histogram chart by using the above parameter. This vector v is plot using
hist().
Output:
A bar chart also known as bar graph is a pictorial representation of data that presents categorical
data with rectangular bars with heights or lengths proportional to the values that they represent.
In other words, it is the pictorial representation of the dataset. These data sets contain the
numerical values of variables that represent the length or height.
Syntax:
Parameters:
• H: This parameter is a vector or matrix containing numeric values which are used in
bar chart.
• xlab: This parameter is the label for x axis in bar chart.
• ylab: This parameter is the label for y axis in bar chart.
• main: This parameter is the title of the bar chart.
• names.arg: This parameter is a vector of names appearing under each bar in bar chart.
• col: This parameter is used to give colors to the bars in the graph.