Calculate mean of multiple columns of R DataFrame
Mean is a numerical representation of the central tendency of the sample in consideration. In this article, we are going to calculate the mean of multiple columns of a dataframe in R Programming Language.
Mean= sum of observations/total number of observations.
Method 1: Using colMeans() function
colMeans() this will return the column-wise mean of the given dataframe.
where dataframe_name is the input dataframe.
For this simply pass the dataframe in use to the colMeans() function. The result will be the mean of all the individual columns.
Method 2: Using sapply() function
where dataframe is the input dataframe and mean is the method to calculate mean.
For this dataframe name needs to be passed along with the action to perform in our case mean.
a b d 3.000 5.000 55.946