13.4 Logic of accessing subsets of data frames
- Same logic as for vectors but two dimensions
- Replace rows/columns by vector indicating position (numerical, logical, character)
- Logic similar for other object classes such as lists (remember vectors/lists)
# Q: What does the following code do? swiss[2:4, c(1,2,4)] # indices, c() necessary when numbers are not connected swiss[swiss$Fertility > 75 & swiss$Agriculture > 75, c(1:3)] subset(swiss, Fertility > 75 & Agriculture > 75)[, c(1:3)] swiss[, c("Fertility", "Agriculture")] # We'll learn a more convenient function later on!