My data frame (df) is:
Year Site1 Site2 Site3
2000 2 4 5
2001 2 5 45
2002 4 4 56
2003 23 67 45
2004 4 4 34
2005 3 56 34
2006 67 12 24
And I want to calculate the mean of the three sites from certain time windows. The periods would be: a)from 2000 to 2006, b) from 2001 to 2006, c) from 2002 to 2006 and d) from 2000 to 2004
The code I used for period "a" is the following:
P <- cbind(df[,2:4]
mean_a <- aggregate(P ~ df[1:7,], mean)
and I get the following:
Error in aggregate.data.frame(as.data.frame(x), ...) : 'by' must be a list