0% found this document useful (0 votes)
2 views4 pages

R Ka Assignment

The document provides a tutorial on plotting histograms using the mtcars dataset in R, focusing on both equal and unequal class intervals for the mpg variable. It explains the steps to load the dataset, create histograms, and interpret the results, highlighting the distribution of fuel efficiency among cars. The unequal intervals allow for targeted analysis of specific MPG categories, contrasting with the equal intervals approach.

Uploaded by

foyidab693
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)
2 views4 pages

R Ka Assignment

The document provides a tutorial on plotting histograms using the mtcars dataset in R, focusing on both equal and unequal class intervals for the mpg variable. It explains the steps to load the dataset, create histograms, and interpret the results, highlighting the distribution of fuel efficiency among cars. The unequal intervals allow for targeted analysis of specific MPG categories, contrasting with the equal intervals approach.

Uploaded by

foyidab693
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/ 4

STATISTICAL DATA ANALYSIS USING R

AKASH RAJ

665

DSE 4
2022-2025

Professor sign
1. Load dataset and plot histogram (equal class
intervals)

Question:
Using the mtcars dataset, plot a histogram for the
mpg variable (miles per gallon) using equal class
intervals. Explain each step and interpret the results.
Solution:-

$ data <- mtcars


$ hist(data$mpg,
$ breaks = 10,
$ main = "Histogram of Miles Per Gallon (MPG)",
$ xlab = "MPG",
$ col = "skyblue")
Explanation :-

 data <- mtcars: We load the built-in dataset


mtcars into a variable called data. This dataset
contains information about 32 cars (rows) and 11 attributes
(columns), such as mpg, hp, wt, etc.
 hist(data$mpg): Plots the frequency of values in
mpg.
 breaks = 10: Divides the range of mpg into 10 equal
intervals (bins).
 main, xlab, and col: These arguments are for better
labeling and color customization

Interpretation:-

 The histogram shows how fuel efficiency (measured in


MPG) is distributed.
 Most cars fall between 15 to 25 MPG.
 The shape of the histogram may be slightly right-skewed
(more low-MPG cars).
 Histogram helps visualize distribution, central tendency,
and spread.
2.Plot histogram (unequal class intervals)

Question:

Plot a histogram for mpg using unequal class intervals: 10–


15, 15–20, 20–25, 25–30, 30–35. Explain how this differs
from equal bins.

Solution :-

$ hist(data$mpg,
$ breaks = c(10,15,20,25,30,35),
$ main = "Histogram with Unequal Intervals",
$ xlab = "Miles Per Gallon",
$ col = "orange")

Explanation:-

 breaks = c(10,15,20,25,30,35): Manually


defines the bin edges.
 Useful when data is not uniformly distributed or when
specific ranges matter (e.g., defining “low”, “medium”,
“high” mpg).

Interpretation:-

$ Shows how many cars fall in each custom MPG category.


$ Unlike equal intervals, this allows you to target specific
thresholds, which might represent fuel standards or policy
levels.

You might also like