我对数据集中的几个类别变量进行了一次相同的转换,并尝试通过循环进行此操作:
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) :
有人可以指导我解决问题吗?