Don't forget to load `lattice` package. `latticeExtra` with `panel.ablineeq` can be also helpful.
This was however for plotting. For subset regression by each WR without plotting you'd use something like `lapply` or `sapply`. ans <- sapply(unique(data$WR), function(dir) { out <- list(lm(PM10~Ref, subset(data, WR=dir))) names(out) <- dir out }) `ans$West` will return one of the results. There are many ways to skin a cat. Perhaps it was not the best one. Mikhail On 08/13/2011 11:30 AM, Dennis Murphy wrote: > Hi: > > Try something like this, using dat as the name of your data frame: > > xyplot(PM10 ~ Ref | WR, data = dat, type = c('p', 'r')) > > The plot looks silly with the data snippet you provided, but should > hopefully look more sensible with the complete data. The code creates > a four panel plot, one per direction, with points and a least squares > regression line fit in each panel. The regression line is specific to > a data subset, not the entire data frame. > > HTH, > Dennis > > On Sat, Aug 13, 2011 at 5:43 AM, maggy yan <kiot...@googlemail.com> wrote: >> dear R users, >> my data looks like this >> >> PM10 Ref UZ JZ WT RH FT WR >> 1 10.973195 4.338874 nein Winter Dienstag ja nein West >> 2 6.381684 2.250446 nein Sommer Sonntag nein ja Süd >> 3 62.586512 66.304869 ja Sommer Sonntag nein nein Ost >> 4 5.590101 8.526152 ja Sommer Donnerstag nein nein Nord >> 5 30.925054 16.073091 nein Winter Sonntag nein nein Ost >> 6 10.750567 2.285075 nein Winter Mittwoch nein nein Süd >> 7 39.118316 17.128691 ja Sommer Sonntag nein nein Ost >> 8 9.327564 7.038572 ja Sommer Montag nein nein Nord >> 9 52.271744 15.021977 nein Winter Montag nein nein Ost >> 10 27.388416 22.449102 ja Sommer Montag nein nein Ost >> >> . >> >> . >> >> . >> >> . >> >> til 200 >> >> >> I'm trying to make a linear regression between PM10 and Ref for each of the >> four WR, I've tried this: >> plot(Nord$PM10 ~ Nord$Ref, main="Nord", xlab="Ref", ylab="PM10") >> but it does not work, because "Nord cannot be found" >> what was wrong? how can I do it? please help me >> >> [[alternative HTML version deleted]] >> >> >> ______________________________________________ >> 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. >> >> > ______________________________________________ > 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. ______________________________________________ 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.