R Statistics

Using built-in functions or external packages you can perform various statistical analyses in R.
We use thse functions to get the statistics for anylazing the data.

Descriptive Statistics

Used for basic mathematical calculations.

Function

Description

Example

mean(x)

Calculates the mean (average) of a numeric vector x.

mean(c(1, 2, 3, 4, 5))

median(x)

Calculates the median of a numeric vector x

median(c(1, 2, 3, 4, 5))

sd(x)

Computes the standard deviation of a numeric vector x.

sd(c(1, 2, 3, 4, 5))

var(x)

Computes the variance of a numeric vector x.

var(c(1, 2, 3, 4, 5))

summary(x)

Provides summary statistics (min, 1st quartile, median, mean, 3rd quartile, max) for a numeric vector x.

summary(c(1, 2, 3, 4, 5))

quantile(x, probs)

Calculates sample quantiles corresponding to given probabilities probs.

quantile(c(1, 2, 3, 4, 5),
probs = c(0.25, 0.5, 0.75))

range(x)

Computes the range (minimum and maximum) of a numeric vector x.

range(c(1, 2, 3, 4, 5))

min(x)

Return the minimum value in the vector x.

min(c(1, 2, 3, 4, 5))

max(x)

Return the maximum value in the vector x.

max(c(1, 2, 3, 4, 5))

length(x)

Returns the number of elements in a vector x.

length(c(1, 2, 3, 4, 5))


Example

# Sample numeric vector
data <- c(22, 30, 25, 40, 35, 28, 45, 50, 32, 38, 42, 27, 33, 29, 31)

# Mean
mean_value <- mean(data)

# Median
median_value <- median(data)

# Standard Deviation
sd_value <- sd(data)

# Variance
variance_value <- var(data)

# Summary Statistics
summary_stats <- summary(data)

# Quantiles
quantiles <- quantile(data, probs = c(0.25, 0.5, 0.75))

# Range
range_values <- range(data)

# Minimum value
min_value <- min(data)

# Maximum Value
max_value <- maz(data)

# Length
length_value <- length(data)

# Display the results
cat("Mean:", mean_value, "\n")
cat("Median:", median_value, "\n")
cat("Standard Deviation:", sd_value, "\n")
cat("Variance:", variance_value, "\n")
cat("Summary Statistics:\n", summary_stats, "\n")
cat("Quantiles:", quantiles, "\n")
cat("Range:", range_values, "\n")
cat("Minimum Value:", min_value, "\n")
cat("Maximum Value:", max_value, "\n")
cat("Length:", length_value, "\n")

Chi-square Test

Used to determine whether there is a significant association between categorical variables.
chi-square test is a statistical test.
It doesn't make assumptions about the distribution of the data.
Commonly used for testing relationships in contingency tables.

Example

# Example data for chi-square test
observed <- matrix(c(10, 20, 15, 5), nrow = 2)

# Chi-square test
chi_square_result <- chisq.test(observed)
chi_square_result

Quick Recap - Topics Covered

R Statistics
Chi-square Test

Practice With Examples in Compilers

The Concepts and codes you leart practice in Compilers till you are confident of doing on your own. A Various methods of examples, concepts, codes availble in our websites. Don't know where to start Down some code examples are given for this page topic use the code and compiler.


Example js

Example 1 Example 2 Example 3 Example 4 Example 5


Quiz


FEEDBACK