0

The following code won't detect the written element and always gives 0 (false) response in the plant column.

ourData <- myData %>% 
mutate(plant = ifelse(description %in% c("⚰️"), 1,0))
View(ourData)

The following code gives data below

ourData_ description

enter image description here

However, it seems to work for the "num_row" column. So I was wondering why this is the case and how I can solve it?

ourData <- myData %>% 
mutate(plant = ifelse(num_row %in% c("1"), 1,0))
View(ourData)

Below is one for num_row (which works)

ourData_num_row

enter image description here

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Kosu K.
  • 75
  • 5
  • 1
    Can you please provide sample input in a [reproducible format](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) rather than an image. We cannot test your code with the image. Note that `%in%` only does complete matches. For example `"a" %in% "cab"` returns false. If you want partial string matching, you probably want something like `grep` or a function from the `stringr` package. – MrFlick Oct 15 '20 at 03:26
  • 2
    As MrFlick said, try with `mydata$plant <- as.integer(grepl("⚰️", myData$description))` – Ronak Shah Oct 15 '20 at 03:43

0 Answers0