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.
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
(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))