Log Transformation of Data Frame in R (Example)


In this article, I’ll demonstrate how to apply a log transformation to all columns of a data frame in the R programming language.

Table of contents:

You’re here for the answer, so let’s get straight to the example…


Example Data

As a first step, we have to create some data that we can use in the example code later on:

data <- data.frame(x1 = 1:5,    # Create example data frame
                   x2 = 11:15,
                   x3 = 10:6)
data                            # Print example data frame


table 1 data frame log transformation data frame r


Table 1 shows that our example data consists of five rows and three columns.


Example: Generate Log Transformation of All Data Frame Columns Using log() Function

This example explains how to perform a log transformation for all columns of a data frame.

For this task, we can apply the log function as shown below:

data_log <- log(data)           # Log transformation
data_log                        # Print log transformed data


table 2 data frame log transformation data frame r


As illustrated in Table 2, we have created a new data frame called data_log, which contains the log transformed values of our input data frame.


Video & Further Resources

Do you want to learn more about the log conversion of all data frame variables? Then you may have a look at the following video tutorial on my YouTube channel. In the video, I’m explaining the examples of this article:



Also, you could have a look at the related RStudio articles on this website. I have published several related articles already.


Summary: In this article, I have explained how to log transform all columns of a data matrix in the R programming language. If you have further questions, please let me know in the comments section below.


Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.

4 Comments. Leave new

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.