DF <- data.frame(Name = LETTERS[1:5], Age = c(34, 22, 67,43, 10))
mean(DF[DF$Age < 30, "Age"])
#> [1] 16
#Why does that work?
DF$Age < 30 #This returns TRUE and FALSE values
#> [1] FALSE TRUE FALSE FALSE TRUE
DF[DF$Age < 30, ] #This returns all rows where the comparison is TRUE
#> Name Age
#> 2 B 22
#> 5 E 10
DF[DF$Age < 30, "Age"] #Tis returns just the Age column of selected rows
#> [1] 22 10