0

First time here:

I need to subset based on data results being >4.9 (and it goes up to 22.2), but R stop subsetting at 9.8 and leaves out 10-22.2. My code:

rha.under.six.total.elevated<- rha.under.six.total[which(rha.under.six.total$lead_level>"4.9"),]
joran
  • 169,992
  • 32
  • 429
  • 468
M.Frumh
  • 15
  • 2
  • 3
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Note that `4.9` is very different from `"4.9"` -- one is a numeric value and one is a character value. They have different rules for sorting. – MrFlick Nov 28 '18 at 21:05
  • I agree that your description stringly (pun intended) suggests that a column that you think is numbers is actually characters, but it's hard to say for sure without a more detailed example to work with. – joran Nov 28 '18 at 21:08

1 Answers1

0

try with this:

rha.under.six.total.elevated <- rha.under.six.total[rha.under.six.total$lead_level>4.9, ]

I think the which() statement is superfluous, you just need a "boolean" condition in order to filter rows. Then you don't need to represent the "4.9" as a character.

Leevo
  • 1,683
  • 2
  • 17
  • 34