I want to calculate the logarithm of total assets, and I want r to set the result to NULL if the total assets element itself is 0. Otherwise, r will show me -Inf as the result. I have tried to solve this problem as follows:
at <- c(0.028, 0, 0, 0, 0, 0)
name <- c("comp 1","comp2", "comp3", "comp4", "comp5", "comp6")
df <- as.data.frame(cbind(name, at))
df$log_at <- ifelse(is.null(at), 0, log(at))
However, if you run this line of code, the column 2 with the log(assets) will then show -3.575551 instead of 0 in each row of the data frame for the NULL values of the total assets. Also, I wanted to know how many NULL values are in the total assets column, but:
sum(is.null(df$at))
will give me 0, so I am wondering why r does not identify the Null values as such, since the values in the total assets column are all numeric.
I know, I can use the following as an alternative since the amounts of total assets are pretty big but I am wondering why the code above does not work.
df$at <- as.numeric(df$at)
df$log_at <- log(df$at + 1)
I hope someone can help me out !