Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

excel_stat_summary_functions

Excel Statistical Summary Functions


Description

15+ common statistical functions familiar to users of Excel (e.g. SUM(), AVERAGE()). These functions return a single value (i.e. a vector of length 1).

These functions are designed to help users coming from an Excel background. Most functions replicate the behavior of Excel:

  • Names in most cases match Excel function names

  • Functionality replicates Excel

  • By default, missing values are ignored (same as in Excel)

Usage

SUM(x)

AVERAGE(x)

MEDIAN(x)

MIN(x)

MAX(x)

COUNT(x)

COUNT_UNIQUE(x)

STDEV(x)

VAR(x)

COR(x, y)

COV(x, y)

FIRST(x)

LAST(x)

NTH(x, n = 1)

CHANGE_FIRSTLAST(x)

PCT_CHANGE_FIRSTLAST(x)

Arguments

x

A vector. Most functions are designed for numeric data. Some functions like COUNT() handle multiple data types.

y

A vector. Used in functions requiring 2 inputs.

n

A single value used in NTH() to select a specific element location to return.

Details

Summary Functions

  • All functions remove missing values (NA). This is the same behavior as in Excel and most commonly what is desired.

Value

  • Summary functions return a single value

Useful functions

Summary Functions - Return a single value from a vector

Examples

# Libraries
library(tidyquant)
library(timetk)
library(tidyverse)
library(forcats)

# --- Basic Usage ----

SUM(1:10)

PCT_CHANGE_FIRSTLAST(c(21, 24, 22, 25))

# --- Usage with tidyverse ---

# Go from daily to monthly periodicity,
# then calculate returns and growth of $1 USD
FANG %>%
    mutate(symbol = as_factor(symbol)) %>%
    group_by(symbol) %>%

    # Summarization - Collapse from daily to FIRST value by month
    summarise_by_time(
        .date_var  = date,
        .by        = "month",
        adjusted   = FIRST(adjusted)
    )

tidyquant

Tidy Quantitative Financial Analysis

v1.0.3
MIT + file LICENSE
Authors
Matt Dancho [aut, cre], Davis Vaughan [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.