[R] cleaning up a vector

Erik Iverson eriki at ccbr.umn.edu
Fri Oct 1 19:58:50 CEST 2010


Mike,

Small, reproducible examples are always useful for the rest of the us.

x <- c(0, NA, NaN, 1 , 10, 20, 21, Inf)
x[!is.na(x) & x >=1 & x<= 20]

Is that what you're looking for?

mlarkin at 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?
> 
> Mike
> 
> ______________________________________________
> R-help at 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.



More information about the R-help mailing list