mtcars
data(mtcars)
head(mtcars)
Loads and displays the first few rows of the mtcars dataset.
str(mtcars)
Displays the structure of the mtcars dataset, showing the type of each column.
summary(mtcars)
Measures of Central Tendency
Mean
Calculates the mean of a sequence of numbers.
n = c(1,2,4,5,6)
print(n)
mean_ = sum(n) / length(n)
print(mean_)
mean_cyl = sum(mtcars$cyl) / length(mtcars$cyl)
print(mean_cyl)
Median
- If ( N ) is odd:
- If ( N ) is even:
Calculates the median of a sequence of numbers with an odd size.
data_even <- c(7, 13, 19, 33, 67)
median_ <- median(data_even)
print(median_)
data_even <- c(7, 13, 19, 33, 67)
n = length(data_even)
median_ <- data_even[(n + 1) / 2]
print(median_)
Calculates the median of a sequence of numbers with an even size.
data_odd <- c(2, 34, 76, 92, 112)
median_ <- median(data_odd)
print(median_)
data_odd <- c(2, 34, 76, 92, 112)
n = length(data_odd)
median_ <- (data_odd[n / 2] + data_odd[n / 2 + 1]) / 2
print(median_)
median(mtcars$cyl)
median(mtcars$qsec)
Mode
Creates a frequency table for a sequence of numbers.
numbers <- c(1, 233, 233, 010101, 342, 1, 2, 1111, 1, 55)
tnumbers <- table(numbers)
print(numbers)
print(tnumbers)
mode_ <- as.numeric(names(tnumbers)[tnumbers == max(tnumbers)])
print(mode_)
Identifies the most frequent value(s) in the sequence of numbers.
library(DescTools)
mode_ <- Mode(tnumbers)
print(mode_)
Measures of Dispersion
Defines a sequence of numbers.
n_arr = c(1,2,4,5,6)
print(n_arr)
Variance
Calculates the variance of a sequence of numbers.
mean_ <- mean(n_arr)
print('Mean')
print(mean_)
print('Variance')
var_ <- sum((n_arr - mean_)^2) / length(n_arr)
print((n_arr - mean_))
print((n_arr - mean_)^2)
print(sum((n_arr - mean_)^2))
print(length(n_arr))
print(var_)
Standard Deviation
Calculates the standard deviation, which is the square root of the variance.
print('Variance')
var_ <- sum((n_arr - mean_)^2) / length(n_arr)
print((n_arr - mean_))
print((n_arr - mean_)^2)
print(sum((n_arr - mean_)^2))
print(length(n_arr))
print(var_)
print('Standard Deviation')
std_ <- sqrt(var_)
print(std_)
Calculates the standard deviation using the sd function in R.
std_ <- sd(n_arr)
print(std_)
Range
Calculates the range, which is the difference between the maximum and minimum values.
range_ <- max(n_arr) - min(n_arr)
print('Range')
print(max(n_arr))
print(min(n_arr))
print(range_)
Calculates the range using the diff function.
range_ <- diff(range(n_arr))
print(range_)
Coefficient of Variation
Calculates the coefficient of variation, which is the ratio of the standard deviation to the mean.
mean_ <- mean(n_arr)
print('Mean')
print(mean_)
print('Variance')
var_ <- sum((n_arr - mean_)^2) / length(n_arr)
print((n_arr - mean_))
print((n_arr - mean_)^2)
print(sum((n_arr - mean_)^2))
print(length(n_arr))
print(var_)
print('Standard Deviation')
std_ <- sqrt(var_)
print(std_)
print('Coefficient of Variation')
cv <- std_ / mean_
print(cv)
My Latest Posts
My Super Powers as a Software Developer - 2024
sc0v0ne ・ Jan 6
Favorites Projects Open Source
- 🐍 Python
- 🖥️ Deep Learning
- 👀 Computer Vision
- 🖥️ Linux
- 📉 Times Series
- 💾 Database
- 🦀 Rust
- 🖥️ Machine Learning
- 🛣️ Roadmaps
About the author:
A little more about me...
Graduated in Bachelor of Information Systems, in college I had contact with different technologies. Along the way, I took the Artificial Intelligence course, where I had my first contact with machine learning and Python. From this it became my passion to learn about this area. Today I work with machine learning and deep learning developing communication software. Along the way, I created a blog where I create some posts about subjects that I am studying and share them to help other users.
I'm currently learning TensorFlow and Computer Vision
Curiosity: I love coffee
Top comments (0)