R
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Data Structures
-
Section 4: Data Manipulation
-
Section 5: Visualization and Statistics
-
Section 6: Advanced R
-
Section 7: Practical Projects
-
Section 8: Interview Practice
-
Section 9: More Practice Exercises
-
Section 10: Shiny Apps in Depth
-
Section 11: More Data Wrangling
-
Section 12: Tidyverse Deep Dive
-
Section 13: Statistical Modeling Deep Dive
-
Section 14: Machine Learning in R
-
Section 15: R Visualization Deep Dive
-
Section 16: R Package Development Deep Dive
-
Section 17: R for Reproducible Research
-
Section 18: R and Databases
-
Section 19: R Performance Optimization
-
Section 20: Bioinformatics and Specialized R
-
Section 21: More Shiny Practice
-
Section 22: More Practice Exercises
-
Section 23: R Data Structures Deep Dive
-
Section 24: More Interview and Review
-
Section 25: R for Business Analytics
-
Section 26: R Text Mining and NLP
-
Section 27: R Spatial Data Analysis
-
Section 28: R Deep Learning
-
Section 29: Advanced Statistical Techniques
-
Section 30: R Object Systems Deep Dive
-
Section 31: R Environments and Metaprogramming
-
Section 32: R for Finance
-
Section 33: R for Clinical and Health Data
-
Section 34: More Shiny Advanced Practice
-
Section 35: R Data Cleaning Deep Dive
-
Section 36: R Reporting Automation
-
Section 37: More Practical Projects Round 2
-
Section 38: R Ecosystem and Career
-
Section 39: More Visualization Practice
-
Section 40: R for Experimentation
-
Section 41: R for Genomics and Bioinformatics Deep Dive
-
Section 42: R for Marketing Analytics
-
Section 43: R Data Import/Export Deep Dive
-
Section 44: R String Processing Deep Dive
-
Section 45: R for Actuarial and Insurance Analytics
-
Section 46: R Testing and Quality Assurance Deep Dive
-
Section 47: R Version Control and Collaboration
-
Section 48: R Advanced Functional Programming
-
Section 49: R for Supply Chain and Operations
-
Section 50: More Practice Exercises Round 3
-
Section 51: R Dashboards and BI Integration
-
Section 52: R Data Governance and Ethics
-
Section 53: More Modeling Practice
-
Section 54: R Final Capstone Projects
-
Section 55: R for Sports Analytics
-
Section 56: More Interview Practice Round 2
-
Section 57: R Networking and APIs
-
Section 58: R for Environmental Science
-
Section 59: R Notebook and Documentation Practices
-
Section 60: More Data Wrangling Mastery
-
Section 61: R for A/B Testing at Scale
-
Section 62: R Package Ecosystem Deep Dive
236: Writing Effective Analysis Documentation
How much prose do I actually need to write?
I've seen a lot of analysts swing between two extremes: they either write zero comments and expect the code to "speak for itself," or they write a novel that buries the actual analysis. Here is the truth: code tells me how you did something, but it rarely tells me why you did it.
If you're using R Markdown or Quarto, your goal isn't to transcribe the code into English. Instead, focus on the transitions. Don't say "Now I am filtering for values over 50" when the code clearly says filter(value > 50). That's noise. Instead, explain the business logic: "We're filtering for values over 50 because that is the WHO threshold for 'Unhealthy' air quality."
Think of it as a narrative. If I can read your text and understand the story of the data without staring at every single line of R code, you've hit the sweet spot.
How do I document the "ugly" data cleaning without ruining the report flow?
We've all been there. You spend three hours wrestling with a CSV that has weird encoding and missing headers, and you end up with a 50-line block of gsub() and mutate() calls. If you put that in the middle of your analysis, you'll lose your reader immediately.
My advice? Use a separate "preprocessing" script for the heavy lifting, or use the echo = FALSE or ref.label options in your chunks to hide the plumbing. If you keep it in the main document, wrap the cleaning in a clearly named function. It turns a wall of noise into a single, readable line.
# Instead of 20 lines of regex in the main flow, do this:
clean_sensor_data <- function(df) {
df %>%
mutate(timestamp = as.POSIXct(timestamp, format = "%Y-%m-%d %H:%M:%S")) %>%
filter(!is.na(pm25)) %>%
# ... all the other messy cleaning here ...
mutate(city = trimws(city))
}
# In the report, it looks clean:
processed_data <- raw_data %>% clean_sensor_data()
Where should I actually put my assumptions?
This is where most people fail. They document the result, but not the assumptions that led to it. When you make a decision—like deciding to treat "N/A" as 0 or dropping outliers beyond 3 standard deviations—that needs to be a first-class citizen in your documentation.
I personally like to use a "Methodology" or "Assumptions" section at the top of the document. If the assumption happens mid-analysis, put it in a callout box or a bolded paragraph immediately preceding the code chunk. If you don't, you'll be the one answering an email six months from now trying to remember why you deleted 15% of your dataset.
How do I stop my documentation from becoming outdated as the code changes?
The moment you write your documentation in a separate Word doc or a Wiki page, it starts dying. The only way to keep documentation "alive" is to keep it physically attached to the code. This is why literate programming (like Quarto) is the gold standard for R analysis.
When the code and the explanation live in the same .qmd or .Rmd file, the friction of updating the text is much lower. Also, try to use inline R code to report your findings. Instead of writing "The average PM2.5 was 12.4," use an inline expression. That way, if the data changes, the documentation updates itself automatically when you render the report.
# Instead of: "The mean air quality index was 45."
# Use: "The mean air quality index was `r round(mean(data$aqi), 1)`."📋 Practical Task
Documenting the Urban Heat Island Analysis
You have been handed a messy R script that analyzes temperature differences between city centers and suburbs. The code works, but it's a "black box"—there are no explanations for why certain filters were applied, and the results are hard-coded into the comments.
Your Task: Transform the provided raw script into a professional analysis document (R Markdown or Quarto style). You must:
- Convert the hard-coded result comments into inline R expressions so the report updates automatically.
- Identify the "cleaning" section and wrap it into a named function to improve readability.
- Add a "Methodology/Assumptions" section explaining why temperatures above 45°C were treated as sensor errors (outliers) and removed.
- Replace "What the code is doing" descriptions (e.g., "Filtering the data") with "Why it is being done" descriptions (e.g., "Removing sensor errors to prevent skewing the mean").
Submit your final .Rmd or .qmd file showing the narrative flow between the code and the analysis.
There are no comments for now.