Logical function not working properly

Very unlikely, I suspect you are just reading the data as factors instead of character strings that is why your code gives an unexpected result.

If you need more specific help, please prepare a reproducible example (reprex) illustrating your issue.

Have a look at this guide, to see how to create one: