Re: [R] Replacing an element in a vector

From: Ivan Calandra <ivan.calandra_at_uni-hamburg.de>
Date: Mon, 28 Feb 2011 14:42:45 +0100

Dear Vincy,

Try this:
C[is.nan(C)] <- 0

HTH,
Ivan

Le 2/28/2011 13:10, Vincy Pyne a écrit :
> Dear R helpers
>
> I seem to have one trivial problem but can't find solution to it.
>
> Suppose I have following input.
>
> A = c(1, 3, 0, 5, 8) # 3rd element is 0
> B = c(100, 30, 0, 25, 40) # 3rd element is 0
>
> C = A/B
>
>> C
> [1] 0.01 0.10 NaN 0.20 0.20
>
> Obviously, I can't divide 0/0 and hence NaN. My problem is how to replace this NaN say by 0.
>
> So that I can have C as
>
> C = c(0.01, 0.10, 0, 0.20, 0.20)
>
> I tried the replace command but can't get rid of NaN.
>
> Kindly guide.
>
> Vincy
>
>
>
> [[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.

-- 
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calandra_at_uni-hamburg.de

**********
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php

______________________________________________
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.
Received on Mon 28 Feb 2011 - 13:57:56 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 Feb 2011 - 15:00:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive