0

I've got a data frame as so,

Treatment Type  Numerical Value
1          A          3
1          B          2
1          A          8
1          B          7
2          B          4
2          B          1
2          A          2
2          A          2

I want to make a table of means for each type and treatments.

Using aggregate, I have: aggregate(df[,3], list(Treatment) ,mean) which gives me the means for each treatment but not separated by type too. I was thinking this could be rectified by a for-loop.

Note: This is just a subset of the data, and the list of numerical values is hundreds for each type and treatment.

Nayuki
  • 17,911
  • 6
  • 53
  • 80
E1993
  • 1
  • 3
  • 1
    ```aggregate(`Numerical Value` ~ Treatment + Type, df, mean)```? Haven't tested but should work – David Arenburg Oct 29 '15 at 19:47
  • Yeah works for the subset, but for some reason when I apply to the whole set I get the error: `Error in eval(predvars, data, env) : numeric 'envir' arg not of length one' – E1993 Oct 29 '15 at 19:59

1 Answers1

0

Since I don't have repu to comment:

aggregate(df, list(Treatment,Type), mean)
TayTay
  • 6,882
  • 4
  • 44
  • 65
Bg1850
  • 3,032
  • 2
  • 16
  • 30