0

I have a table in R that looks like this:

"Dimension","Config","Result"
"3","1","6.43547800901942e-12"
"3","1","3.10671396584125e-15"
"3","1","5.86997050075184e-07"
"3","2","1.57865350726808"
"3","2","0.125293574811717"
"3","2","0.096173751923243"
"4","1","3.33845065295529e-08"
"4","1","4.57511389653726e-07"
"4","1","2.58918409465438e-07"
"4","2","3.23375251723051"
"4","2","2.13142950121767"
"4","2","0.510008166587752"

As it can be observed, I always have 6 values for each dimension, and for each dimension I have 3 values for config 1 and 3 values for config 2. Is it possible to "double aggregate" this table so it would output the means for config 1 for each dimension and the mean for config 2 for each dimension as well?

If I use this comand line:

a <- aggregate(d[,3], list(d$Dimension), mean) 

I get this result:

   Group.1            x
1        3 3.000202e-01
2        4 9.791985e-01

But I want something like this:

   Group.1  Config              x
1        3       1   <mean value for this row>
2        3       2   <mean value for this row>
3        4       1   <mean value for this row>
4        4       2   <mean value for this row>
Marcos Guimaraes
  • 1,243
  • 4
  • 27
  • 50

1 Answers1

1

You can use the formula interface.

d <- read.table(text="Dimension,Config,Result
                3,1,6.43547800901942e-12
                3,1,3.10671396584125e-15
                3,1,5.86997050075184e-07
                3,2,1.57865350726808
                3,2,0.125293574811717
                3,2,0.096173751923243
                4,1,3.33845065295529e-08
                4,1,4.57511389653726e-07
                4,1,2.58918409465438e-07
                4,2,3.23375251723051
                4,2,2.13142950121767
                4,2,0.510008166587752", header=T, sep=',')

aggregate(Result ~ Dimension+Config, data=d, mean) 
  Dimension Config       Result
1         3      1 1.956678e-07
2         4      1 2.499381e-07
3         3      2 6.000403e-01
4         4      2 1.958397e+00
bobbel
  • 1,983
  • 6
  • 21