adplus-dvertising
frame-decoration

Question

Which of the following R code can be used to avoid numeric problems such as taking the logarithm of a negative number?

a.

if( any(x < 0) ) y <- log(1+x) else y <- log(x)

b.

if( any(x <= 0) ) y <- log(1+x) else y <- log(x)

c.

if( any(x >= 0) ) y <- log(1+x) else y <- log(x)

d.

if( any(x >> 0) ) x >- log(1+x) else x <- log(x)

Posted under R Programming

Answer: (b).if( any(x <= 0) ) y <- log(1+x) else y <- log(x)

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. Which of the following R code can be used to avoid numeric problems such as taking the logarithm of a negative number?