Because k-fold cross validation gets exactly one prediction per case (row) in each run, you can easily collect the predictions in a vector (or matrix, for more iterations/repetitions and/or multiple predicted values per case):
library(earth)
library(pls)
set.seed(1)
k <- 10;
folds <- cvsegments(nrow(trees), k);
result <- rep (NA, nrow (trees))
for (fold in 1 : k){
currentFold <- folds[[fold]]
fit = earth(Volume ~ ., data=trees[-currentFold,])
result [currentFold] <- predict(fit, trees[currentFold,]);
}
You can then look at the results at your leisure:
> plot (trees$Volume, result)
> head (cbind (trees, pred.Vol = result))
Girth Height Volume pred.Vol
1 8.3 70 10.3 9.701729
2 8.6 65 10.3 10.627089
3 8.8 63 10.2 10.737521
4 10.5 72 16.4 16.313330
5 10.7 81 18.8 21.297516
6 10.8 83 19.7 22.408600