For R: (1) instead of `sapply(nba, mean, na.rm = TRUE)` use `colMeans(nba, na.rm = TRUE)`. (2) instead of `nba[, c(&quot;ast&quot;, &quot;fg&quot;, &quot;trb&quot;)]` use `nba[c(&quot;ast&quot;, &quot;fg&quot;, &quot;trb&quot;)]`, (3) instead of   `sum(is.na(col)) == 0`  use `!anyNA(col)`, (4) instead of `sample(1:nrow(nba), trainRowCount)` use `sample(nrow(nba), trainRowCount)` and (5)
instead of tons of code use `library(XML); readHTMLTable(url, stringsAsFactors = FALSE)`