[R] Fw: Do GLM by groups

Benilton Carvalho bcarvalh at jhsph.edu
Thu Jul 19 19:26:36 CEST 2007


Check the following example for by():

      require(stats)
      attach(warpbreaks)
      by(warpbreaks, tension, function(x) lm(breaks ~ wool, data = x))

or just type:
example(by)

b


On Jul 19, 2007, at 1:18 PM, Hongmei Jia wrote:

>
> Dear All,
>
> I'm trying to do 'glm' analysis by groups just like in SAS you use "by
> variable".   I don't know how to do it in R, anyone can help with  
> this?
> i.e.
>
> group    line  rep  value
> 1              1       1       0.2
> 1              1       2       0.3
> 1     1       3       0.23
> 1             2       1       0.2
> 1             2       2       0.3
> 1             2      3       0.23
> 2              1       1       0.2
> 2              1       2       0.3
> 2     1       3       0.23
> 2             2       1       0.2
> 2             2       2       0.3
> 2             2      3       0.23
>
> in SAS we say:
> model value=line rep;
> by group;
>
> How can I do this in R?
>
> Thanks,
>
> Hongmei Jia
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.



More information about the R-help mailing list