-3

How to just extract the cells where the values are lower than 0 including NAs ?

I would like to have a vector as an output.

Rechlay
  • 1,457
  • 2
  • 12
  • 19
  • 4
    And we would like you to: A: provide a reproducible example. B: Use Google before posting basic R questions – David Arenburg May 14 '14 at 09:54
  • 1
    http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – nico May 14 '14 at 09:54
  • Tried google but didn't know what's the proper question... Thx for your help. Just think about creating a thread about "reproducible answer". – Rechlay May 14 '14 at 09:58

1 Answers1

1

Have a look at the way to subset items from a vector using ?'['

> set.seed(0)
> x <- c(rnorm(10),NA)
> x
 [1]  1.262954285 -0.326233361  1.329799263  1.272429321  0.414641434
 [6] -1.539950042 -0.928567035 -0.294720447 -0.005767173  2.404653389
[11]           NA
> x[x<0 |is.na(x)]
[1] -0.326233361 -1.539950042 -0.928567035 -0.294720447 -0.005767173
[6]           NA
Miff
  • 7,486
  • 20
  • 20