# UCL R tutoring - Lesson 1 - Instructor demonstration
# Created: 2026-10-30 | v1.0 | Base R only
# Data below are synthetic examples, not real student records.

# 1. Expressions and variables
print(5 + 3 * 2)
score <- 75
print(score)

# 2. A vector: values of the same basic type
marks <- c(40, 60, 70, 90)
print(marks)
print(length(marks))
print(mean(marks))
print(max(marks))
print(marks[2])       # R uses 1-based indexing
print(marks[marks >= 70])

# 3. Make a small synthetic data frame
student_id  <- paste0("S", 1:8)
study_hours <- c(1, 2, 2, 3, 4, 4, 5, 6)
quiz_score  <- c(42, 48, 55, 62, 69, 74, 82, 90)
group       <- c("A", "B", "A", "B", "A", "B", "A", "B")
class_data <- data.frame(student_id, study_hours, quiz_score, group)

print(head(class_data))
str(class_data)
print(names(class_data))
print(dim(class_data))
print(summary(class_data))

# 4. Summaries
print(mean(class_data$quiz_score))
print(median(class_data$quiz_score))
print(mean(class_data$study_hours))

# 5. Plot: points show observations; association is NOT proof of causation
plot(class_data$study_hours, class_data$quiz_score,
     xlab = "Study hours", ylab = "Quiz score",
     main = "Illustrative synthetic data", pch = 19)

# Optional bonus: subgroup average, no extra packages
print(mean(class_data$quiz_score[class_data$group == "A"]))

# Ask the learner to save and re-run this whole script.
