Subsets of vectors or data frames Note that: na.omit(x) generates x, less NAs. But it does more. It keeps traceback information on what elements were omitted. > x <- c(1, 5, NA, 2, 0, 11) > xy <- data.frame(x=x, y=letters[1:6]) > na.omit(x) [1] 1 5 2 0 11 attr(,"na.action") [1] 3 attr(,"class") [1] "omit" > ## Try also na.omit(xy) The object that is returned retains traceback information, in the attributes, on what has been done. na.exclude() has almost the same effect [the difference affects the way that information in the object may be returned later] > na.exclude(x) [1] 1 5 2 0 11 attr(,"na.action") [1] 3 attr(,"class") [1] "exclude" Information on the class is used by some modeling functions to determine whether residuals etc are returned for all data [class="exclude"] or [with class="omit"] only for non-missing data. Or you can do, e.g. > keep <- !is.na(x) & x!=0 > x[keep] [1] 1 5 2 11 > ## Alternative > subset(x, keep) [1] 1 5 2 11 > ## Try also > # xy[keep, ] > # subset(xy, keep) Part V, 4(d) To regress log(weight) on log(thick) and 0.5*(log(height)+log(breadth)), the model formula needed is log(weight) ~ log(thick) + I(0.5*(log(height)+log(breadth))) The reason for the use of the wrapper function I() is to prevent the parser from giving "*" the special meaning that it has in a model formula. Part VI Note that fitted() and residuals() and other such functions are applied to model objects, i.e., for lm models, to the output from lm(....)