[R] How to transform matrices to ANOVA input datasets?

szhan at uoguelph.ca szhan at uoguelph.ca
Wed Mar 14 19:11:38 CET 2007


Hello, R experts,
I have a list called dataHP which has 30 elements (m1, m2, ..., m30).  
Each element is a 7x6 matrix holding yield data from two factors  
experimental design, with treatment in column, position in row. For  
instance, the element 20 is:
dataHP[[20]]
           col1     col2     col3      trt1     trt2    trt3
  [1,]     22.0     20.3     29.7      63.3     78.5    76.4
  [2,]    102.4     92.3     72.2     199.2    201.1    218.9
  [3,]     18.8     20.8     22.9     106.2    148.4    147.6
  [4,]     14.5     17.2     15.6     120.1    115.8    124.6
  [5,]     31.9     28.3     22.8     157.9    192.3    160.6
  [6,]     98.2    147.3    102.5     628.8    577.0    643.0
  [7,]    174.9    217.5   188.66     453.5    491.1    409.8

My goal is to find which element in the list has significant yield  
difference among the position. So my first question is how to  
transform the matrix to ANOVA input dataset which is:
yield	block	treat	position
22	1	col	1
102.4	1	col	2
18.8	1	col	3
14.5	1	col	4
31.9	1	col	5
98.2	1	col	6
174.9	1	col	7
20.3	2	col	1
92.3	2	col	2
20.8	2	col	3
17.2	2	col	4
28.3	2	col	5
147.3	2	col	6
217.5	2	col	7
29.7	3	col	1
72.2	3	col	2
22.9	3	col	3
15.6	3	col	4
22.8	3	col	5
102.5	3	col	6
188.66	3	col	7
63.3	1	trt	1
199.2	1	trt	2
106.2	1	trt	3
120.1	1	trt	4
157.9	1	trt	5
628.8	1	trt	6
453.5	1	trt	7
78.5	2	trt	1
201.1	2	trt	2
148.4	2	trt	3
115.8	2	trt	4
192.3	2	trt	5
577	2	trt	6
491.1	2	trt	7
76.4	3	trt	1
218.9	3	trt	2
147.6	3	trt	3
124.6	3	trt	4
160.6	3	trt	5
643	3	trt	6
409.8	3	trt	7
So I can contrasts(position) and do ANOVA like this:
fit1<-aov(yield~treat*position)
summary(fit1, split=list(position=1:10), expand.split= T)
Finally I can find the significant element in the list if there is any  
significant contrast among the position. So my second question is how  
to apply this ANOVA to each element in the list?
Your help will be highly appreciated!!

Josh



More information about the R-help mailing list