1

I’m having trouble putting two conditions into a subset. The result is a whole bunch of NA.

> df[(df$col > 0) && (df$col < 4), ]
alistaire
  • 42,459
  • 4
  • 77
  • 117

1 Answers1

0

Drop the space after ',' and you only need one '&'.

df[df$col > 0 & df$col < 4,]

You may be getting NA 'cause you want OR (|) instead of AND (&).

Alberson Miranda
  • 1,248
  • 7
  • 25
  • 2
    *"Drop the space after ',' "* The extra whitespace has nothing to do with the issue. in fact, for readability and to be consistent with common R coding style recommendations, it's better to keep the whitespace after the comma. You are correct in pointing out the difference between `&` and `&&`. See also [Boolean operators && and ||](https://stackoverflow.com/questions/6558921/boolean-operators-and). – Maurits Evers Oct 21 '19 at 04:27
  • The single ampersand did the trick. Thanks! (White space had no effect.) – Johnny Williamson Oct 21 '19 at 15:32