Is this random forest logical correct and correct implemented with R and gbm?
Is the code correct?
Yes, it looks correct to me

How to calculate Errors:
Calculate accuracy for train data
Calculate accuracy for test data


If train error is high (RMSE in your case) - high bias, retrain model with more trees, less learning rate, more data (if possible)
If train error low, but test error high - high variance or overfit: regularization, increase k-fold
If tran and test error low - your model is good to go.
Hope this answeres your question.