Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the asgaros-forum domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home1/mbithide/public_html/wp-includes/functions.php on line 6121

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the health-check domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home1/mbithide/public_html/wp-includes/functions.php on line 6121
How to Perform Descriptive Statistics in R (With Examples) - Mbithi Guide
How to Perform Descriptive Statistics in R

Descriptive statistics play a crucial role in understanding and summarizing the main features of a dataset. They provide a concise summary of the essential characteristics of the data, such as central tendency, dispersion, and shape of the distribution.

Common measures of descriptive statistics include mean, median, mode, standard deviation, range, and quartiles.

Descriptive Statistics in R

1. mean()

The mean() function calculates the arithmetic mean of a numeric vector.

# Calculate the mean of a numeric vector
data <- c(10, 15, 20, 25, 30)
mean_value <- mean(data)
print("Mean:")
print(mean_value)
[1] "Mean:"
> print(mean_value)
[1] 20

Check out our online statistics calculators for FREE

2. median()

The median() function calculates the median (middle value) of a numeric vector.

# Calculate the median of a numeric vector
median_value <- median(data)
print("Median:")
print(median_value)
[1] "Median:"
> print(median_value)
[1] 20

3. sd() – Standard Deviation

The sd() function calculates the standard deviation, which measures the amount of variation or dispersion in a set of values.

# Calculate the standard deviation of a numeric vector
standard_deviation <- sd(data)
print("Standard Deviation:")
print(standard_deviation)
[1] "Standard Deviation:"
> print(standard_deviation)
[1] 7.905694

4. summary()

The summary() function provides a summary of the statistical properties of a dataset, including the minimum, maximum, median, and quartiles.

# Generate a summary of a dataset
summary_data <- summary(data)
print("Summary:")
print(summary_data)
[1] "Summary:"
> print(summary_data)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
     10      15      20      20      25    

5. quantile()

The quantile() function calculates the quartiles of a dataset.

# Calculate quartiles
quartiles <- quantile(data)
print("Quartiles:")
print(quartiles)
[1] "Quartiles:"
> print(quartiles)
  0%  25%  50%  75% 100% 
  10   15   20   25   30 

By Benard Mbithi

A statistics graduate with a knack for crafting data-powered business solutions. I assist businesses in overcoming challenges and achieving their goals through strategic data analysis and problem-solving expertise.