R Basics – Data Analysis Part 3 – Statistics

Wczytaliśmy dane i sprawdziliśmy ich poprawność. Poznajmy kilka funkcji pozwalających je w prosty sposób przeanalizować. Do analizy wykorzystamy plik z ludnością w powiatach, który wczytywaliśmy w części pierwszej (pobierz). Wczytajmy go ponownie:

We have loaded the data and validated it. Let’s explore some features to analyze it in a simple way. For the analysis, we will use the file with population in districts that we loaded in the first part (download). Let us load it again:

First, in the population column, we want to find the maximum population in the districts. To do this, we will use the max function:

Using the expression we used in the previous post, we can display the name of the county with the highest population:

The minimum population is displayed using the min function:

The least populated district is:

If we want to know the minimum and maximum value of the data at once, we can use the range function:

The mean function is used to calculate the average value:

We will find the median using the median function:

The standard deviation will give us the sd function:

And the variance of var:

We will count quartiles with the quantile function for which we need to determine which one:

We can use the summary function to display basic statistics for specific values:

It is also useful to use the aggregate function to analyze values in groups. In our case, for example, by province. Let’s use this function to calculate the average population in counties by province. As arguments we have to specify values, then we group the calculations as a list (by) and which function we want to use in the calculations (FUN).

R has a lot of functions that are useful for data analysis, because that’s what it was created for. We just wanted to show the basic ones. If you want to deepen your knowledge in this area, we refer you to the documentation, which contains very detailed descriptions of each function. In the next post we will show how to display data in charts.

Leave a Reply

Your email address will not be published.

Translate using Google Translate»
Social media & sharing icons powered by UltimatelySocial

Podoba Ci się nasza strona? Odwiedź nasz profil