This is a didactic example on stacking.
Some info: You 'll find stacking algorithm i implemented in this book: Data mining Pratical machine learning tools and techniques ( pag 303) ( you can download it for free somewhere, don't stop looking up ;). ( by the way It's a very good book for other purposes)
This is a simple stacking model that takes two model at level 0( ridge regression and random forest) and has a linear regression on level 1. you can refine it by adding some code in order to use every type of model in the algorithm. Maybe a use of caret package will be very helpful in this code. I apply the code to a very simple dataset, Boston house, which is located in MASS library. I take medv variable( median house value) as our target variable.
Hope someone we'll see it and appreciate! bye