s-news
[Top] [All Lists]

Re: How to replace NAs and Inf

To: Chushu Gu <chushugu@hotmail.com>
Subject: Re: How to replace NAs and Inf
From: Spencer Graves <spencer.graves@pdf.com>
Date: Sun, 28 Sep 2003 20:54:57 -0500
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <Law11-OE44ENePEpwcx00007ea4@hotmail.com>
References: <Law11-OE44ENePEpwcx00007ea4@hotmail.com>
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)
How about:
> a <- c(1, NA, Inf)
> abs(a) == Inf
[1] FALSE    NA  TRUE
> a[is.na(a)|(abs(a)==Inf)] <- 0
> a
[1] 1 0 0

hope this helps.  spencer graves

Chushu Gu wrote:

I got a vector
[1] 0.003009027 0.008088979 0.011247444 0.014522822 0.022269353 0.031728665 0.030439684 0.043529412 0.037851038 0.035398230 0.057486631 [12] 0.040333797 0.055800294 0.070754717 0.056478405 0.067375887 0.084615385 0.090146751 0.089041096 0.100502513 0.075675676 0.114457831 [23] 0.110367893 0.087272727 0.091269841 0.115044248 0.135678392 0.143678161 0.144736842 0.169230769 0.214953271 0.163043478 0.210526316 [34] 0.070422535 0.224137931 0.160000000 0.136363636 0.189189189 0.156250000 0.230769231 0.181818182 0.157894737 0.266666667 0.250000000 [45] 0.333333333 0.125000000 0.000000000 0.142857143 0.166666667 1.000000000 0.000000000 0.500000000 1.000000000 0.000000000 0.000000000 [56] Inf NA NA NA NA NA NA NA NA NA NA [67] NA NA NA NA NA NA NA NA NA NA NA [78] NA NA NA NA NA NA NA NA NA NA NA [89] NA NA NA NA NA NA NA NA NA NA NA [100] NA NA NA NA NA NA NA NA NA NA NA I want to replace all the NAs and Infs with 0 Thanks



<Prev in Thread] Current Thread [Next in Thread>