0

I have a data set(for eg:iris) and I need to calculate Mean, Median mode and need to find the outliers

this should be a function in a generic way.So that whenever I use this function for any data set it should automatically calculate all the uni variate statistics.

  • 2
    Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – Sotos Aug 08 '18 at 09:00

2 Answers2

0

As far as existing functions go, summary() is a quick way to get various descriptive statistics such as mean, median and min/max values (which can be used for determining outliers) for variables in your dataset.

Taking the example of iris dataset:

>summary(iris)

    Sepal.Length    Sepal.Width     Petal.Length    Petal.Width          Species  
    Min.   :4.300   Min.   :2.000   Min.   :1.000   Min.   :0.100   setosa    :50  
    1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600   1st Qu.:0.300   versicolor:50  
    Median :5.800   Median :3.000   Median :4.350   Median :1.300   virginica :50  
    Mean   :5.843   Mean   :3.057   Mean   :3.758   Mean   :1.199                  
    3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100   3rd Qu.:1.800                  
    Max.   :7.900   Max.   :4.400   Max.   :6.900   Max.   :2.500

As for the mode, you'll have to write your own function - you can find some guidance here at Tutorials Point.

One last point, I'd take Sotos's advice, it's really beneficial for yourself and other Stack users.

Thanks!

Pryore
  • 510
  • 9
  • 22
0

You could also try using the dataMaid package to get an overview of your data. That will produce a report with information for each variable in a data frame, but it may not be exactly what you are after.

library("dataMaid")
makeDataReport(iris)

Here's a snippet from the report produced:

enter image description here

ekstroem
  • 5,957
  • 3
  • 22
  • 48