On Fri, Oct 1, 2010 at 10:51 AM,  <mlar...@rsmas.miami.edu> wrote:
> I calculated a large vector.  Unfortunately, I have some measurement error
> in my data and some of the values in the vector are erroneous.  I ended up
> wih some Infs and NaNs in the vector.  I would like to filter out the Inf
> and NaN values and only keep the values in my vector that range from 1 to
> 20.  Is there a way to filter out Infs and NaNs in R and end up with a
> clean vector?
>

Two steps, starting from vector x

x1 = x[is.finite(x)];
x2 = x1[(x1 <= 20) & (x1 >= 1)];

>From what you say, x2 is the result you want. Just be aware  that
dropping values will change the indexing.

Peter

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to