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

P 1

The 'mtcars' dataset contains 32 observations and 11 variables, including 'mpg', 'cyl', 'disp', and 'hp'. It provides summary statistics, frequency tables for selected variables, and a variance-covariance matrix to analyze relationships between variables. Key insights include measures of central tendency, variability, and potential correlations useful for predicting car species.

Uploaded by

Triveni Jayaram
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)
7 views4 pages

P 1

The 'mtcars' dataset contains 32 observations and 11 variables, including 'mpg', 'cyl', 'disp', and 'hp'. It provides summary statistics, frequency tables for selected variables, and a variance-covariance matrix to analyze relationships between variables. Key insights include measures of central tendency, variability, and potential correlations useful for predicting car species.

Uploaded by

Triveni Jayaram
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

# Load the 'mtcars' dataset

data(mtcars)

# 1. Dataset Dimensions and Structure

cat("Dimensions of the dataset:", dim(mtcars), "\n")

cat("Names of the variables:", names(mtcars), "\n")

cat("Name of each car (first column):\n")

print(rownames(mtcars))

cat("Number of rows:", nrow(mtcars), "\n")

cat("Number of columns:", ncol(mtcars), "\n")

cat("Summary of the dataset:\n")

print(summary(mtcars))

# 2. Frequency Tables

cat("\nFrequency table for 'mpg':\n")

print(table(cut(mtcars$mpg, breaks = seq(10, 40, by = 5))))

cat("\nFrequency table for 'wt':\n")

print(table(cut(mtcars$wt, breaks = seq(1.5, 5.5, by = 0.5))))


cat("\nFrequency table for 'disp':\n")

print(table(cut(mtcars$disp, breaks = seq(70, 500, by = 50))))

cat("\nFrequency table for 'hp':\n")

print(table(cut(mtcars$hp, breaks = seq(50, 350, by = 50))))

# 3. Mean and Standard Deviation

cat("\nMean and Standard Deviation:\n")

cat("mpg: Mean =", mean(mtcars$mpg), ", SD =", sd(mtcars$mpg), "\n")

cat("wt: Mean =", mean(mtcars$wt), ", SD =", sd(mtcars$wt), "\n")

cat("disp: Mean =", mean(mtcars$disp), ", SD =", sd(mtcars$disp), "\n")

cat("hp: Mean =", mean(mtcars$hp), ", SD =", sd(mtcars$hp), "\n")

# 4. Variance-Covariance Matrix

cat("\nVariance-Covariance Matrix:\n")

print(var(mtcars[, c("mpg", "wt", "disp", "hp")]))

# Interpretation

cat("\nInterpretation:\n")

cat("- The 'mtcars' dataset has 32 rows (observations) and 11 columns (variables).\n")

cat("- The variables include 'mpg' (miles per gallon), 'cyl' (number of cylinders), 'disp'
(displacement), 'hp' (horsepower), and others.\n")

cat("- The first column contains the names of the cars.\n")

cat("- The 'summary()' function provides a concise overview of each variable.\n")

cat("- Frequency tables show the distribution of values for each variable within specified
intervals.\n")

cat("- Mean and Standard Deviation provide measures of central tendency and variability.\
n")
cat("- 'mpg' and 'wt' might be good candidates for guessing car species due to potential
correlations with car size and engine type.\n")

cat("- The variance-covariance matrix shows the variance of each variable and the
covariance between pairs.\n")

cat("- Positive covariance indicates variables tend to increase/decrease together.\n")

cat("- Negative covariance suggests that as one variable increases, the other tends to
decrease.\n")

> # Load the 'mtcars' dataset

> data(mtcars)

>

> # 1. Dataset Dimensions and Structure

> cat("Dimensions of the dataset:", dim(mtcars), "\n")

Dimensions of the dataset: 32 11

> cat("Names of the variables:", names(mtcars), "\n")

Names of the variables: mpg cyl disp hp drat wt qsec vs am gear carb

> cat("Name of each car (first column):\n")

Name of each car (first column):

> print(rownames(mtcars))

[1] "Mazda RX4" "Mazda RX4 Wag" "Datsun 710"

[4] "Hornet 4 Drive" "Hornet Sportabout" "Valiant"

[7] "Duster 360" "Merc 240D" "Merc 230"

[10] "Merc 280" "Merc 280C" "Merc 450SE"

[13] "Merc 450SL" "Merc 450SLC" "Cadillac Fleetwood"

[16] "Lincoln Continental" "Chrysler Imperial" "Fiat 128"

[19] "Honda Civic" "Toyota Corolla" "Toyota Corona"

[22] "Dodge Challenger" "AMC Javelin" "Camaro Z28"


[25] "Pontiac Firebird" "Fiat X1-9" "Porsche 914-2"

[28] "Lotus Europa" "Ford Pantera L" "Ferrari Dino"

[31] "Maserati Bora" "Volvo 142E"

> cat("Number of rows:", nrow(mtcars), "\n")

Number of rows: 32

> cat("Number of columns:", ncol(mtcars), "\n")

Number of columns: 11

You might also like