Skip to content
Prev 336111 / 398513 Next

aggregate()?

Hello,

First of all avoid as.data.frame(cbind(...)). cbind() returns a matrix 
and since you are mixing numbers with characters, all of the matrix 
elements become character. Then as.data.frame transforms everything into 
factors. The correct way is

d <- data.frame(Stock, Soil, Nitrogen, Respiration)


As for your question, try the following.

r1 <- aggregate(Respiration ~ Soil + Stock, data = d, mean)
r2 <- aggregate(Nitrogen ~ Soil + Stock, data = d, mean)

merge(r1, r2, all = TRUE)


Hope this helps,

Rui Barradas

Em 02-02-2014 12:32, Beatriz R. Gonzalez Dominguez escreveu: