filter() not working on categorical variable

dplyr

#1

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!


#2

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


#3

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:


#4

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


#5

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