R:knnImputation产生错误 [英] R : knnImputation Giving Error

查看:423
本文介绍了R:knnImputation产生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在R编码中遇到错误.

在我的Brand_X.xlsx数据集中,我尝试使用KNN插补来计算的NA值很少,但是却低于错误.怎么了谢谢!

in my Brand_X.xlsx dataset, there are few NA values which I am trying to compute using KNN imputation but I am getting below error. whats wrong here? Thanks!

> 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
>

推荐答案

我今天遇到了问题,我发现我们应该将tbl对象转换为data.frame对象!!这是令人讨厌的一点,即不同的软件包没有兼容性.

I came into the problem today,and I found that we should transform our tbl object into data.frame object!!This is one disgusting point that different packages do not have compatibility.

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

这篇关于R:knnImputation产生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆