[R] Cannot clean infinite values
Ben Bolker
bolker at ufl.edu
Mon Apr 27 04:41:05 CEST 2009
Nigel Birney wrote:
>
> Hello all,
>
> I have to import numeric data from file but found it contains Infinite
> values which need to be eliminated. I tried to replace them in this way:
>
> data[which(data=="-Inf")] <- -0.3
> data[which(data=="+Inf")] <- 0.3
>
> But, somehow, the Infinite values stayed there. Any suggestions?
>
>
Inf is a special value -- it shouldn't be in quotation marks
> z <- c(1/0,0/0,-1/0)
> z
[1] Inf NaN -Inf
> z[z==Inf] <- 0.5
> z[z==-Inf] <- -0.5
or ...
> z <- c(1/0,0/0,-1/0)
> z[is.infinite(z)] <- 0.5*sign(z[is.infinite(z)])
> z
[1] 0.5 NaN -0.5
--
View this message in context: http://www.nabble.com/Cannot-clean-infinite-values-tp23248409p23249234.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list