filter() not working on categorical variable

I am using the filter() function to extract rows from a data frame. When I try to extract based on a numerical variable , it works fine.

filter(Data, Weight == 50)

However, when I try via a categorical failure, I receive an error message

filter(Data, Sex == M)

"Error in filter_impl(.data, quo) : Evaluation error: comparison of these types is not implemented"

I am doing this in rmarkdown, not sure if that makes a difference.

Thanks!

Try
filter(Data, Sex == "M")

5 Likes

To expand on Martin's solution, categorical values (either character or levels of factors) need to be wrapped in quote marks in R :slightly_smiling_face:

1 Like

hah! of course. I'm telling you, this is what happens when you use R once in a blue moon. thanks.

If your question's been answered (even if by you), would you mind choosing a solution? (See FAQ below for how).

Having questions checked as resolved makes it a bit easier to navigate the site visually and see which threads still need help.

Thanks

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.