DEV Community

Cover image for 10 Essential Data Calculations in R Every Analyst Should Know
Cristiano Gabrieli
Cristiano Gabrieli

Posted on

10 Essential Data Calculations in R Every Analyst Should Know

Most analytical work relies on a small set of core calculations.
Master these 10 operations in R and you’ll cover 80% of real‑world dashboards, reports, and automation tasks.

Below is a clean, practical guide with minimal theory and maximum usefulness.

  1. Sum, Mean, Median r x <- c(10, 20, 30, 40)

sum(x)
mean(x)
median(x)

  1. Grouped Calculations (dplyr) r library(dplyr)

df %>%
group_by(region) %>%
summarise(
avg_sales = mean(sales),
total = sum(sales)
)

  1. Percent Change r percent_change <- (new - old) / old * 100
  2. Rolling Calculations r library(zoo)

rollmean(df$value, k = 7, fill = NA)

  1. Cumulative Calculations r cumsum(x) cumprod(x)
  2. Ranking & Percentiles r rank(x) quantile(x, probs = 0.9)
  3. Row‑wise Calculations r rowSums(df) rowMeans(df)
  4. Conditional Calculations r df %>% mutate(score = case_when( value > 90 ~ "High", value > 70 ~ "Medium", TRUE ~ "Low" ))
  5. Correlation & Covariance r cor(df$x, df$y) cov(df$x, df$y)
  6. Mini KPI Block r df %>% summarise( total = sum(value), avg = mean(value), pct_change = (last(value) - first(value)) / first(value) * 100, p90 = quantile(value, 0.9) )

Tools & Resources
Payhip Store:

https://payhip.com/CrisDigital

Gumroad Store:

https://gabrieli112.gumroad.com

Top comments (0)