R : knnImputation Giving Error

标签 r statistics data-science knn

在 R 编码中出现以下错误。

在我的 Brand_X.xlsx 数据集中,我尝试使用 KNN 插补法计算的 NA 值很少,但我得到的结果低于错误。这里有什么问题吗?谢谢!

> library(readxl)
> Brand_X <- read_excel("Brand_X.xlsx")
> str(Brand_X)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame':   101 obs. of  8 variables:
 $ Rel_price_lag5: num  108 111 105 103 109 104 110 114 103 108 ...
 $ Rel_price_lag1: num  110 109 217 241 855 271 234 297 271 999 ...
 $ Rel_Price     : num  122 110 109 217 241 855 271 234 297 271 ...
 $ Promo         : num  74 29 32 24 16 31 22 7 32 22 ...
 $ Loy_HH        : num  37 26 35 30 26 26 31 20 34 20 ...
 $ Nonloy_HH     : num  46 70 55 54 54 59 55 56 57 45 ...
 $ Week          : num  56 57 58 59 60 61 62 63 64 65 ...
 $ Share_X       : num  25 23 50 33 22 44 29 17 41 27 ...
> 
> library(DMwR)
> 
> anyNA(Brand_X)
[1] TRUE
> 
> knnImputation(Brand_X)
Error: Column indexes must be at most 1 if positive, not 22, 25, 37, 8, 47, 2, 50, 40, 52, 67
>

最佳答案

See my previous answer

今天遇到问题,发现要把我们的tbl对象转成data.frame对象!!这是一个恶心的点,不同的包不兼容。

#check your df class,I think your df is actually as tbl object
class(df)
df_new <- as.data.frame(df)

关于R : knnImputation Giving Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45117125/

相关文章:

r - 如何根据向量值在点图中使用不同的符号

r - 如何在 Azure 上交互式运行 Docker 容器

github - 如何获取 GitHub 克隆统计信息?

r - 如何解决predict()中的错误: subscript out of bounds in R when doing binary classification?

python - 无法读取列车数据

r - 在数据框中的多行上提取具有匹配模式的 id

python - 什么是如何阅读 TensorBoard 的直方图特征的一个很好的解释?

python - 计算每行的列平均值,不包括计算平均值的行

python - 尝试合并不同 Excel 文件中的列

r - 更改时间序列中指定间隔的线型(实线到虚线)