I'm using kaggle's pokemon data to practice KNN imputation via preProcess()
, but when I did I encountered this following message after the predict()
step. I am wondering if I use the incorrect data format or if some columns have inappropriate "class." Below is my code.
library(dplyr)
library(ggplot2)
library(tidyr)
library(reshape2)
library(caret)
library(skimr)
library(psych)
library(e1071)
library(data.table)
pokemon <- read.csv("https://www.dropbox.com/s/znbta9u9tub2ox9/pokemon.csv?dl=1")
pokemon = tbl_df(pokemon)
# select relevant features
df <- select(pokemon, hp, weight_kg, height_m, sp_attack, sp_defense, capture_rate)
pre_process_missing_data <- preProcess(df, method="knnImpute")
classify_legendary <- predict(pre_process_missing_data, newdata = df)
and I received this error message
Error: Must subset rows with a valid subscript vector.
x Subscript `nn$nn.idx` must be a simple vector, not a matrix.
Run `rlang::last_error()` to see where the error occurred.
df
is also ofdata.frame
class, but it seems that itstbl
property is interferring thepreProcess()
. Many thanks! – Arbogast