R ifelse statement only return number

情到浓时终转凉″ 提交于 2020-04-18 05:31:01

问题


This is house$room

type<-c('2室1厅','2室2厅','3室2厅','1室1厅','4室2厅',
        '3室1厅','1室','2室','1室2厅','5室2厅','4室3厅')

Why does ifelse return only numbers?


回答1:


It could be that house$room is factor and it gets coerced to integer storage values within the ifelse loop. One option is to convert to character class

ifelse(house$room %in% type, as.character(house$room), '不要张贴图片')


来源:https://stackoverflow.com/questions/49586086/r-ifelse-statement-only-return-number

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!