replace infinite values by mean of log transformed variable

Hello guys,

Im currently taking my master thesis.

i want to log transform a variable. the output gives me the following variables: i would like to replace the infinite values and 0 values by the mean of the log transformed variable.

any idea?

thanks in advance

I'm not sure why you want to replace the zeros, since 0 == log(1). But you could adapt something like

z <- rnorm(10) # fake data
meanLog  <- mean(log(z[which(z>=0)])) # take mean of valid logs

logz <- ifelse( is.infinite(log(z)), meanLog, log(z))

Hey,
thanks for the help.
you are right, replacing zeros makes no sense, but for the infinite values, i was looking for an answer
i tried the code but i get NaN now. the code above is the one i run as posted here initially

my thoughts:

(z <- rnorm(10)) # fake data
#replace negative values with infinite values so it looks like logpatentstock
(flogpatentstock <-ifelse(z<0,-Inf,z))

# z was faked logpatentstock , so the meanlog is mean of the positive logpatatentstock ? 
(meanLog  <- mean(flogpatentstock[flogpatentstock>=0]))
# apply the fix
(fixed_flogpatentstock <- ifelse( is.infinite(flogpatentstock), meanLog, flogpatentstock))

@nirgrahamuk's code is a little cleaner than mine. Try his.

The other possibility is that acq_patent_stock and master$acq_patent_stock are not the same variables.

it worked out, thank you very much & @startz !

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.