[R] functions and multiple levels

chris20 bop07crb at sheffield.ac.uk
Wed Aug 18 16:38:14 CEST 2010



Hi,
I am trying to write a function;
I want to subtract the mean of each class in level 2 from the mean of each
class in level 1 and square the answer, eg.....

   level.1      level.2      observation
      1             1                 0.5
      1             1                 0.2 
      1             2                 0.6
      1             2                 0.4
      2             3                 0.8
      2             3                 0.7
      2             4                 0.6
      2             4                 0.4

(mean(1$level.1) - mean(1$level.2))^2
(mean(1$level.1) - mean(2$level.2))^2

etc.....

I want to write a function because I have lots of levels and lots of
different observations.
I thought this should be easy (it's my first attempt at writing a function)
but I just can't work it out!

Thanks
Chris 
-- 
View this message in context: http://r.789695.n4.nabble.com/functions-and-multiple-levels-tp2329935p2329935.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list