Kyan
Kyan

Reputation: 99

R ifelse statement only return number

This is house$room enter image description here

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

enter image description here

Why does ifelse return only numbers?

Upvotes: 1

Views: 1531

Answers (2)

Mahesh Kulkarni
Mahesh Kulkarni

Reputation: 120

Try this:

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

Upvotes: 0

akrun
akrun

Reputation: 887048

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), '不要张贴图片')

Upvotes: 5

Related Questions