2

I have the following data.

 X_vegesum     X_bmi5cat
     53         Obese
     148     Underweight
     643    Normal weight
     167    Normal weight

In the second column, I have a value "Normal weight" which is having a space in it. Now when I try to filter out only "Normal weight" values using the following code, I get NULL answer.

data%>% filter(X_bmi5cat == 'Normal Weight')

I get 0 rows for this filtering. Perhaps, there is a space in 'Normal Weight'. It is working fine for other values with no space.

AK K Khan
  • 41
  • 7
  • 3
    Nope! You were looking for upper-case `W` but your data shows lower-case. If you want case-insensitive, try either `tolower(X_bmi5cat) == "normal weight"` (make sure to down-case the comparison string), or look at regex options (not necessary here) such as `grepl("normal weight", X_bmi5cat, ignore.case=TRUE)`. – r2evans Feb 05 '19 at 05:49
  • 1
    Though this isn't a cosmic question, @RonakShah, this is not a duplicate of `trimws`. – r2evans Feb 05 '19 at 05:50
  • I tried the 'trimws' but it is not working. – AK K Khan Feb 05 '19 at 05:51
  • @r2evans..This helped. Thanks – AK K Khan Feb 05 '19 at 05:54
  • @r2evans yes, you are right. I was just blind. I have reopened the question but not sure if it should be a typo or duplicate of https://stackoverflow.com/questions/36842828/ignore-case-in-dplyr-package – Ronak Shah Feb 05 '19 at 06:13

0 Answers0