Get the App
SLTechnology News&Howtos  ›  Development  › 

How to calculate the average and median in R language

Shulou Source: shulou.com Published: 2022-06-02 01:13:04 10月03日 Update

This article mainly introduces how to use R language to calculate the average and median related knowledge, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to calculate the average and median in R language. Let's take a look.

Mean () calculates the average by finding the sum of the data set and dividing it by the total sum of the sum number to get the average function mean () which is used to calculate the average in R language. The basic syntax used to calculate the average in R is-mean (x, trim = 0, na.rm = FALSE,...).

Mean () to find the average

The average value is obtained by finding the sum of the data set and dividing it by the total sum of the sum number.

The function mean () is used to calculate the average in the R language.

Grammar

The basic syntax used to calculate the average in R is-

Mean (x, trim = 0, na.rm = FALSE,...)

The following is a description of the parameters used-

X is the input vector.

Trim is used to discard observations from both ends of the sort vector.

Na.rm is used to remove missing values from the input vector.

Apply pruning option

When the trim parameter is provided, the values in the vector are sorted and the required observations are subtracted from the calculated average.

When trim = 0.3, the three values from each end are subtracted from the calculation to find the mean.

Apply NA option

If there is a missing value, the average function returns NA.

To remove missing values from the calculation, use na.rm = TRUE. This means removing the na value.

Median () to find the median

The innermost value in the data series is called the median. Use the median () function in the R language to calculate this value.

Grammar

The basic syntax for calculating the median in R language is-

Median (x, na.rm = FALSE)

The following is a description of the parameters used-

X is the input vector.

Na.rm is used to remove missing values from the input vector.

This is the end of the article on "how to calculate the average and median in R language". Thank you for reading! I believe that everyone has a certain understanding of "how to use R language to calculate the average and median" knowledge, if you want to learn more knowledge, welcome to follow the industry information channel.

Tags: Average language median vector grammar function input parameter data knowledge missing content total article find apply sort observe both ends median Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Huawei MySQL NVidia Redmi