How to log-transform variable in actual dataset?

I know how to log-transform a histogram, but how do I apply such a transformation to the actual variable in the dataset? I've searched Google but all the results pertain to viewing transformed data, not actually transforming it.

I know that I can just define an object, such as "log_variable <- log(variable)," but I'm running ANOVA and I don't know if or how I can run it on an object and not the dataset variable itself.

Thanks!

Are you looking for a way to have a logged version of the variable as a column in your data frame? Then you just need to assign it to the data frame when you do the transformation:

data$variable_log <- log(data$variable)

And then call data$variable_log instead of data$variable when you run your ANOVA.

If you want to overwrite the existing values in the dataframe:

data %>%
mutate_at(vars(variable_here), ~log(.))

(I should note that the mutate_at() approach will be soft-deprecated with dplyr 1.0.0)

And if you want to create a new variable in the dataframe holding the logged values:

data %>%
mutate(log_var = log(variable_here))

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