Skip to content

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) β†’

Ozone Solar.R Wind Temp Month Day
1 41 190 7.4 67 5 1
2 36 118 8.0 72 5 2

Q13 β€” Number of observations

nrow(airquality) β†’ 153


Q14 β€” Last two rows

tail(airquality, 2) β†’

Ozone Solar.R Wind Temp Month Day
152 18 131 8.0 76 9 29
153 20 223 11.5 68 9 30

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

subset <- airquality[airquality$Ozone > 31 & airquality$Temp > 90, ]
mean(subset$Solar.R, na.rm=TRUE)

β†’ β‰ˆ 212.8


Q19 β€” Mean Temp when Month==6

mean(airquality$Temp[airquality$Month == 6])

β†’ β‰ˆ 79.1


Q20 β€” Max Ozone in May (Month==5)

max(airquality$Ozone[airquality$Month == 5], na.rm=TRUE)

β†’ 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, ]