想将ifelse用于statemet块,它将替换多列中的值
代码如下
字段是包含是否值的数据框的列名
fields = c('PhoneService', 'OnlineSecurity', 'OnlineBackup', 'DeviceProtection', 'TechSupport',
'StreamingTV', 'StreamingMovies', 'PaperlessBilling' )
for(field in fields){
#print(field)
new_name = as.name(field)
dataset$new_name = ifelse(dataset$new_name == 'No', 0, 1 )
}
我遇到错误
Error in `$<-.data.frame`(`*tmp*`, "new_name", value = logical(0)) :
replacement has 0 rows, data has 7043