Descriptive Statistics in R Programming


Introduction

Descriptive statistics summarize and provide insights into data. In R, functions such as mean(), median(), sd(), and quantile() help calculate these statistics. This tutorial provides step-by-step examples.

1. Mean

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

Example:

    # Calculate mean
    data <- c(10, 20, 30, 40, 50)
    average <- mean(data)
    print(average)
        

2. Median

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

Example:

    # Calculate median
    data <- c(10, 20, 30, 40, 50)
    mid_value <- median(data)
    print(mid_value)
        

3. Standard Deviation

The sd() function calculates the standard deviation, which measures data spread.

Example:

    # Calculate standard deviation
    data <- c(10, 20, 30, 40, 50)
    std_dev <- sd(data)
    print(std_dev)
        

4. Quantiles

The quantile() function calculates the quantiles of a numeric vector, including quartiles.

Example:

    # Calculate quantiles
    data <- c(10, 20, 30, 40, 50)
    quants <- quantile(data)
    print(quants)
        

5. Summary Function

The summary() function provides a quick overview of descriptive statistics for a numeric vector.

Example:

    # Get summary statistics
    data <- c(10, 20, 30, 40, 50)
    summary_stats <- summary(data)
    print(summary_stats)
        

Conclusion

R provides several functions to compute descriptive statistics, allowing you to summarize data effectively. Use these functions to gain insights into your datasets.





Advertisement