Error in xtrain[, c("amount", "duration")] : subscript out of bounds

This selects all rows of xtrain for the two named columns. If one or both of the columns are missing by that spelling, you would see this error. See the FAQ: How to do a minimal reproducible example reprex for beginners for how to attract more helpful answers.