I have a data set (Orig.data) of multiple columns: 1st col = subjects, and subsequent columns are factors (Factor1, Factor2,...) with each factor having 2 levels (A & B for Factor1, 1 & 2 for Factor2, for example); and then the results in different columns (dependent variables).
Each condition consisted of two trials. So the first two rows represent trial 1&2 of Subject1, Factor1-A, Factor2-1, 3rd and 4th rows are the trials of Sub1 Factor1-A, Factor2-2, 5th and 6th rows are Sub1 of Factor1-B, Factor2-1, and so on.
I want to calculate the mean of the first two rows, next two rows, and so on. Using the code below, I get, structurally, the output that I want, but the calculation is completely off:
MySummaryFunc <- function(x) {c(mean = mean(x, na.rm = T), len = sum(!is.na(x)))}
data_avg = summaryBy(Depend.Var1 ~ Subject + Factor1 + Factor2,
data = Orig.data,
FUN = MySummaryFunc, keep.names = TRUE)
Can somebody help me how to fix the problem?