[R] Relase positive with log and zero of negative with 0

rkevinburton at charter.net rkevinburton at charter.net
Sun Nov 15 16:18:18 CET 2009


This is a very simple question but I couldn't form a site search quesry that would return a reasonable result set.

Say I have a vector:

x <- c(0,2,3,4,5,-1,-2)

I want to replace all of the values in 'x' with the log of x. Naturally this runs into problems since some of the values are negative or zero. So how can I replace all of the positive elements of x with the log(x) and the rest with zero?

Thank you.

Kevin




More information about the R-help mailing list