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

plot(xtrain[,c("amount","duration")],
col=c(4,3,6,2)[germancr[train,"installment"]],
pch=c(1,2)[as.numeric(ytrain)],
main="Predicted Default, by 3 Nearest Neighbors", xlab="Amount", ylab="Duration",cex.main=.95)
points(xnew[,c("amount","duration")],
bg=c(4,3,6,2)[germancr[train,"installment"]],
pch=c(21,24)[as.numeric(nearest3)],cex=1.2,col=grey(.7))
legend("bottomright",pch=c(1,16,2,17),bg=c(1,1,1,1),
legend=c("data 0","pred 0","data 1","pred 1"),
title="default",bty="n",cex=.8)
legend("topleft",fill=c(4,3,6,2),legend=c(1,2,3,4),
title="installment %", horiz=TRUE,bty="n",col=grey(.7),cex=.8)

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.

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.