توضیح 1
The live starter code is self-contained and uses only runner-compatible functions.
Loading
درس 1 از 22
Move from a business question to an auditable result with objects, functions, inspection, and clear interpretation.
Motivation
R is most useful when each command serves a question. This opening workflow keeps the source, calculation, output, interpretation, and limitation visible instead of treating code as an isolated trick.
Why this matters
Move from a business question to an auditable result with objects, functions, inspection, and clear interpretation.
Packages and data
Base R. The book uses the frozen Canadian macro table; this browser lab uses a small embedded inflation vector because the separate source-data package was not supplied.
توضیح 1
The live starter code is self-contained and uses only runner-compatible functions.
توضیح 2
Book-only outputs are labelled when the separate source dataset or advanced package was not supplied.
توضیح 3
R code, paths, function names, and formulas remain left-to-right in every locale.
اصطلاحات
A named value stored in the R session.
inflation <- c(2.1, 3.4, 2.8)
A reusable operation called with arguments.
mean(inflation)
Question → data → code → output → interpretation → limitation.
Keep code and decisions together.
نمادگذاری و فرمولها
sample mean = (x1 + ... + xn) / n
The mean is a descriptive summary of the observations supplied to R; it is not automatically a population truth.
مثال حلشده
سناریو
What is the typical inflation rate in a small teaching extract, and which observation is largest?
بررسی با R
inflation <- c(2.1, 2.8, 3.4, 4.2, 3.0, 2.5)
print(summary(inflation))
print(mean(inflation))
print(which.max(inflation))Within this six-observation teaching extract, inflation averages 3.00%, and the fourth observation is the largest. Limitation: The extract is deliberately small and embedded for practice; it does not reproduce the book's full 114-month frozen dataset.
Visual
Six embedded observations used by the live lab.
ارتباط با R
Run the self-contained starter code in the protected STATLAB R runner. The code prints an auditable result and avoids network or unrestricted file access.
Live R Lab
Run a self-contained example, verify its output, and explain one limitation for a first analysis in r.
Ready to run
Common mistake
Do not quote a number without its unit, period, and source. Also remember that R is case-sensitive.
STATLAB Tip
Inspect structure and boundary rows before calculating. A plausible answer can still come from the wrong column.
تمرین هدایتشده
سناریو
Change one inflation value, predict the direction of the mean before running the code, then verify and explain the change.
Compare your result with the definition, units, and model assumptions—not only with a target number.
Exercises
Complete these without looking at the selected solutions. More than one defensible program may exist.
توضیح 1
Create a vector of five monthly rates and calculate its mean and median.
توضیح 2
Use which.max() to identify the largest value.
توضیح 3
Write one sentence distinguishing the sample result from a population claim.
Selected solutions
These are compact solution routes. Confirm dimensions, units, and any changed modelling choices.
توضیح 1
x <- c(1.9, 2.2, 2.7, 3.1, 2.6); c(mean = mean(x), median = median(x))
توضیح 2
which.max(x) returns the position of the maximum.
توضیح 3
A defensible sentence names the observed sample and avoids generalizing beyond it.
Chapter summary
Move from a business question to an auditable result with objects, functions, inspection, and clear interpretation.
توضیح 1
Assign values with <-.
توضیح 2
Inspect before modelling.
توضیح 3
Print auditable results.
توضیح 4
Interpret in context and state a limitation.
اصطلاحات
assign a value
Use in A First Analysis in R.
combine values
Use in A First Analysis in R.
quick diagnostics
Use in A First Analysis in R.
locate a maximum
Use in A First Analysis in R.
References and provenance
Safavi (2026), Introduction to R, Chapter 1; Statistics Canada CPI attribution is documented in the student notes. Student notes: Mohammad Safavi, Ph.D., STATLAB Academy, Version 1.0.
منبع
The authoritative 125-page English PDF accompanies this native lesson.
دریافتبازاندیشی
Name the assumption, evidence you would seek, and how the recommendation might change.
ارزیابی پایانی