R folks, As an R novice, I struggle with the mystery of subsetting. Textbook and online examples of this seem quite straightforward yet I cannot get my mind around it. For practice, I'm using the code in MASS Ch. 6, "whiteside data" to analyze a different data set with similar variables and structure. Here is my data frame:
###subset one of three cases for the variable 'position' >data.b<-data.a[data.a$position=="inrow",] > print(data.b) position porosity x y 1 inrow macro 1.40 16.5 2 inrow macro . . . . . . . . . . 7 inrow micro 8 inrow micro Now I want to do separate lm's for each case of porosity, macro and micro. The code as given in MASS, p.141, slightly modified would be: fit1 <- lm(y ~ x, data=data.b, subset = porosity == "macro") fit2 <- update(fit1, subset = porosity == "micro") ###simplest code with subscripting fit1 <- lm(y ~ x, data.b[porosity=="macro"]) ###following example in ?subset fit1 <- lm(y ~ x, data.b, subset(data.b, porosity, select=macro)) None of th above, plus many permutations thereof, works. Can anyone educate me? Thanks, Robert Walters ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.