x [list] <-值中的错误:'symbol'类型的对象不可子集化

时间:2020-04-26 15:47:42

标签: r loops categorical-data

我对数据集中的几个类别变量进行了一次相同的转换,并尝试通过循环进行此操作:

factor_features<-function(feature){
  data <- data %>%
    mutate(
            feature = replace(feature, is.na(feature), 0),
            feature =  ifelse(feature==1,1, 0)) 
 }

variables<-c("smoking_allowed", "pets_allowed")

for (i in variables){
      factor_features(as.name(i))
}

我的错误是

Error in x[list] <- values : object of type 'symbol' is not subsettable
In addition: Warning messages:
1: In is.na(feature) :
  is.na() applied to non-(list or vector) of type 'symbol'
2: In is.na(feature) :

有人可以指导我解决问题吗?

0 个答案:

没有答案