Finding the natural log in R?

Hello! I'm very new to using R and I'm trying to create a new variable that is the natural log of the number of patients (which is a column of data in my data set) +1 so that I can get -Inf if there are 0 number of patients when logged.

I've been trying to figure this out for a while and I can't seem to get anywhere, any help would be greatly appreciated. Thank you!

If I've understood correctly, you have a data frame that might have a column of patients that looks like this:

df <- data.frame(patients = sample(0:2, 10, replace = T))
df

# in base R, you can just create a new variable column like so:

df$log_of_patients_plus_one <- log(df$patients)+1

If that's not what you're looking for, you might need to give a more detailed example, as well as what output you're looking for.

Thank you very much!

Here is a paper titled "Do not log transform count data."

https://besjournals.onlinelibrary.wiley.com/doi/full/10.1111/j.2041-210X.2010.00021.x

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