i

R Programming Complete Tutorial

Mean & Median

Statistical Analysis:

We will now shed light on Statistical functions, where we will go through the necessary measurements and tests of statistics. We will start with basic mean and median function; then, we will follow the standard deviation and normal distribution in detail. The next section will focus on correlation and finally finish the session with statistical tests, a T-test, and chi-squared test.

Mean & Median

Mean:

Statistical Mean is the same as the average in mathematics. We can calculate it by adding all the data points and dividing by the number of data points. In R-Pro, we use the mean ( ) function to return the mean of a data set.

It is determined by taking the sum of the values and dividing them with the number of values.The function mean() is used to calculate this in R.

In mean function, we mainly use three arguments; the first one is for the data source, sometimes we use trim to drop some unwanted observations, and finally, we can remove Null values just to set na.rm=TRUE. This mean function will return the mean of the mpg data set.

Syntax:

Example:

Median

The median is the middle number. We can calculate it by ordering all the data points and picking out the one in the middle. If there are two middle numbers, we will take the mean of those two numbers.

We use the median function to find out the median of a data set, similar to mean, the syntax of median contains ra.rm = arguments to handle the null values. In a data series, the middle most value is considered the median.To calculate this value, R uses the median () function.

This is an example to find out the median from mpg data.

Syntax:

Example: