Home » Uncategorized

Functions for basics statistics in R

How to have our basic statistics (Mean, Median, SD, Var, Cor, Cov) computed using R language?

The dataottam team has come up with blog sharing initiative called “Celebrate the Big Data Problems”. In this series of blogs we will share our big data problems using CPS (Context, Problem, Solutions) Framework.


In statistics Mean, Median, Standard Deviations, Variance, Correlation, or Covariance are foundations steps. From Data Analyst to Data Scientist they will use the basic statistics. It can be arrived using many languages. But here we will use the language called R.

  • Mean – The mean is the average of the numbers. And it’s easy to calculate; add up all the numbers, then divide by how many numbers there are. In another words it is the sum divided by the count.
  • Median – The median is the middle of a sorted list of numbers. To find the median, place the numbers in value order and find the middle.
  • Standard Deviation – SD is a measure of how spreads out numbers are. And the symbol for SD is sigma, a greek letter.
  • Variance – The Variance is a measure of how spread out numbers are and it is the average of the squared difrences from mean.
  • Correlation- The Corereltion is when two sets of data  are strongly linked together we say they have a high correlation. Correlation is positive when the values increase together, and it is negative when one value decreases as the other increases.
  • Covariance – covariance is a measure of how much two random variables change together.


How to have our basic statistics Mean, Median, Standard Deviation, Variance, Correlation, and Covariance are computed using R language.


Use the below functions as applies with assumptions of x and y are vectors.

  • mean(x)
  • median(x)
  • sd(x)
  • var(x)
  • cor(x,y)
  • cov(x,y)

Big Thank You – R Cookbook, Paul Teetor .

Leave a Reply

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