(2) Core Data Structures and Summaries – Practical

(2) Core Data Structures and Summaries – Practical

Complete every step in order. The Next button unlocks only after each step is checked.

Step 1 / 6

Step 1: Create vectors and factor

Build baseline objects.

heights <- c(10.2,11.1,10.8,11.4,10.9,12.0,12.5,12.2,12.8,12.3)
treatment <- factor(rep(c("Control","Treatment"), each = 5))

Step 2: Build data frame

Combine columns into a tidy table.

df <- data.frame(
  plant_id = 101:110,
  treatment = treatment,
  height_cm = heights,
  leaf_count = c(6,7,6,8,7,8,9,8,9,10)
)

Step 3: Inspect structure

Verify data types before summaries.

str(df)
summary(df)

Step 4: Compute grouped summaries

Calculate means by treatment group.

aggregate(height_cm ~ treatment, data = df, FUN = mean)
aggregate(leaf_count ~ treatment, data = df, FUN = mean)

Step 5: Check category counts

Validate levels and sample sizes.

table(df$treatment)
unique(df$treatment)

Step 6: Interpret results

Write one sentence interpretation for each table.

# Interpretation
# Treatment mean height is ...
# Sample size balance is ...
Great work. You completed all steps in this practical.