Here's a solution with ddply
from the plyr
package:
library(plyr)
ddply(d, .(Stock, Soil, Nitrogen), summarise,
Respiration = mean(as.numeric(as.character(Respiration))))
# Stock Soil Nitrogen Respiration
# 1 A Blank <NA> 112.5
# 2 A Clay 20 138.0
# 3 A Control 0 125.0
# 4 B Blank <NA> 110.0
# 5 B Clay 20 135.0
# 6 B Control 0 123.0
Please note that cbind
is not a good way to create a data frame. You should use data.frame(Stock, Soil, Nitrogen, Respiration)
instead. Due to your approach, all columns of d
are factors. I used as.numeric(as.character(Respiration))
to obtain the numeric values of this column.