[R] How to replace Inf by zero?
Don MacQueen
macq at llnl.gov
Fri May 29 16:26:14 CEST 2009
Although, in this case, the which() is unnecessary.
x[x==Inf] <- 0
See the online help, that is,
help('[')
and also the documentation, "An Introduction to R", available online at CRAN.
-Don
At 2:58 PM +0100 5/29/09, marlene marchena wrote:
>Thanks a lot Andrea, it works!
>
>Marlene.
>
>2009/5/29 Andrea Weidacher <da09ml at yahoo.de>
>
>> Hi Marlene,
>>
>> try this:
>>
>> x[which(x==Inf)] <- 0
>>
>> Andrea.
>>
>> ------------------------------
>> *Von:* marlene marchena <marchenamarlene at gmail.com>
>> *An:* R-help at r-project.org
>> *Gesendet:* Freitag, den 29. Mai 2009, 15:17:57 Uhr
>> *Betreff:* [R] How to replace Inf by zero?
>>
>> Hi R users,
>>
>> Someone knows how to replace Infinite value by zero. I have a vector with
>> some Inf value and I want to substitute these values by zero to get the
>> mean
>> of the components of the vector.
>>
>> Any idea?
>>
>> Many thanks,
>>
>> Marlene.
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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.
>>
>>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>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.
--
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062
More information about the R-help
mailing list