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? regards, N. -- View this message in context: http://www.nabble.com/Cannot-clean-infinite-values-tp23248409p23248409.html Sent from the R help mailing list archive at Nabble.com.
Use ?is.infinite inf <- is.infinite(data) data[inf] <- 0.3 * sign(data[inf]) On Sun, Apr 26, 2009 at 5:44 PM, Nigel Birney <nan23 at cam.ac.uk> 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? > > regards, > > N. > -- > View this message in context: http://www.nabble.com/Cannot-clean-infinite-values-tp23248409p23248409.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >
?is.infinite Charles Annis, P.E. Charles.Annis at StatisticalEngineering.com phone: 561-352-9699 eFax: 614-455-3265 http://www.StatisticalEngineering.com -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Nigel Birney Sent: Sunday, April 26, 2009 8:45 PM To: r-help at r-project.org Subject: [R] Cannot clean infinite values 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? regards, N. -- View this message in context: http://www.nabble.com/Cannot-clean-infinite-values-tp23248409p23248409.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.
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.5or ...> 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.