I have a data set like this:
index1 index2 var1 var2
1 1 1 -3.1175877 -0.9776574
2 2 2 -0.6531706 -0.2230984
3 3 1 0.7909643 -0.1172342
4 4 2 -1.8195348 -0.1111046
5 5 1 -0.5132456 -1.1177841
6 6 2 -0.4288158 0.9268719
with more variables than in my example set here. Index1 and Index2 are factors and I would like to apply the mean function to all of them after grouping all rows by index1 and index2. So for each combination of index1 and index2 I want the corresponding mean of the variables.
I have found a lot of similar questions on StackOverflow using aggregate, tapply, by etc but for some reason the very similar examples there don't seem to work for me. For example:
aggregate(vis, by=list(vis$index1, vis$index2), mean)
gives a warning for each row complaining "argument is not numeric or logical: returning NA" and the resulting data frame contains index1 and index2 columns with nothing but NAs.
Any help appreciated :)