Week 1 Quiz:R Programming(Data Science Specialization):Answers2025
Q1 β Rβs language origin
π R is a dialect of the S language developed at Bell Labs (not Lisp or Scheme).
π§© Concept: R inherited syntax & semantics from S; itβs not a Lisp dialect.
Q2 β βFree softwareβ freedoms
The four freedoms (0β3) are:
0οΈβ£ Run program for any purpose
1οΈβ£ Study how it works, modify it
2οΈβ£ Redistribute copies
3οΈβ£ Improve and share improvements
β Not included: restricting source code, limiting user purposes.
Q3 β Atomic data types
Atomic = single data type elements: numeric, integer, logical, complex, character.
β Not atomic: list, table, matrix, data.frame, array (composite types).
Q4 β x <- 4L
Suffix L makes integer literal.
βοΈ class(x) β "integer"
Q5 β x <- c(4, TRUE)
R coerces mixed types β numeric dominates.
βοΈ Output class: "numeric"
Q6 β rbind(x, y)
Combines vectors row-wise.
x & y each length 3 β 2 rows Γ 3 cols.
βοΈ Shape: 2 Γ 3 matrix.
Q7 β Vector property
All elements must be same class.
βοΈ Homogeneous type constraint.
Q8 β x <- list(2, "a", "b", TRUE) β x[[2]]
[[2]] extracts 2nd element directly.
βοΈ Returns "a" (character vector length 1).
Q9 β Vector recycling
x = 1:4, y = 2:3 β shorter vector repeated:
(1+2, 2+3, 3+2, 4+3) = 3,5,5,7
βοΈ Recycled addition; warning may occur.
Q10 β Set elements <6 to 0
Syntax: x[x < 6] <- 0
βοΈ Thatβs the valid way; several incorrect variations shown.
Q11 β Dataset column names
From airquality dataset:
βοΈ Ozone, Solar.R, Wind, Temp, Month, Day
Q12 β First two rows
Use head(airquality, 2) β
Q13 β Number of observations
nrow(airquality) β 153
Q14 β Last two rows
tail(airquality, 2) β
Q15 β Ozone value in 47th row
airquality[47, "Ozone"] β 21
Q16 β Missing values in Ozone
sum(is.na(airquality$Ozone)) β 37
Q17 β Mean Ozone (excluding NAs)
mean(airquality$Ozone, na.rm=TRUE) β β 42.1
Q18 β Mean Solar.R where Ozone >31 & Temp >90
β β 212.8
Q19 β Mean Temp when Month==6
β β 79.1
Q20 β Max Ozone in May (Month==5)
β 97
π‘ Bonus: Useful Commands Recap
| Concept | Command |
|---|---|
| View first rows | head(df, n) |
| View last rows | tail(df, n) |
| Row count | nrow(df) |
| Column names | names(df) |
| Missing count | sum(is.na(df$column)) |
| Conditional mean | mean(df$col[df$cond], na.rm=TRUE) |
| Subset | df[df$cond, ] |