This is done very easily (added check for NaN):
d <- c(1, -1, 3, -2, 0, NaN) positives <- d[d>0 & !is.nan(d)] negatives <- d[d<0 & !is.nan(d)]
If you want to exclude both NA and NaN, is.na () returns true for both:
d <- c(1, -1, 3, -2, 0, NaN, NA) positives <- d[d>0 & !is.na(d)] negatives <- d[d<0 & !is.na(d)]
source share