How to get the samples in each leaf? (in R xgboost package)

Hi,

By using R xgboost package, can I get to know which leaves the testing sample is in for each tree?
And find out the training sample which in the same leaves as the testing sample?
So that I can do more research of the xgboost model

Thank you.

You can set predleaf=True in predict method.

Thanks for your answer! I can easily get the leaf ID!