R language

Is R only one of the multiple programming languages available on the market or is it much more? It looks like its becoming world phenomenon! We can definitely say that R revolutionised analytics and predictive modelling…

R became the most important tool for visualization of Statistics and Data science. Worldwide community of statisticians and data scientists are using R to resolve the most challenging problems. Complex data can be analysed and visualized with charts and graphs that are part of R.

As part of this exercise we had to create User case and analyse data. As well, as use R graphics to visualize the data.

For starting point we were using R course from Code School – http://tryr.codeschool.com/.

Code school free online course was great starting point to get introduction to R but once I started to work on my User case I realized how big R is!

Numerous websites and tutorials are available and still it didn’t prove as easy as it looks at first instance but I suppose nothing worth a challenge is easy…

I flew through Code school tutorial that covered below points:

1. “R Syntax:A gentle introduction to R expressions, variables, and functions In this first chapter, we’ll over basic R expressions. We’ll start simple, with numbers, strings, and true/false values. Then we’ll show you how to store those values in variables, and how to pass them to functions. We’ll show you how to get help on functions when you’re stuck. Finally we’ll load an R script in from a file.

2.Vectors:Grouping values into vectors, then doing arithmetic and graphs with themThe name may sound intimidating, but a vector is simply a list of values. R relies on vectors for many of its operations. This includes basic plots – we’ll have you drawing graphs by the end of this chapter (and it’s a lot easier than you might think)!

3.Matrices:Creating and graphing two-dimensional data setsSo far we’ve only worked with vectors, which are simple lists of values. What if you need data in rows and columns? Matrices are here to help.A matrix is just a fancy term for a 2-dimensional array. In this chapter, we’ll show you all the basics of working with matrices, from creating them, to accessing them, to plotting them.

4.Summary Statistics:Calculating and plotting some basic statistics: mean, median, and standard deviationThe median is calculated by sorting the values and choosing the middle one (for sets with an even number of values, the middle two values are averaged).Call the median function on the vector:median(limbs)

5.Factors:Creating and plotting categorized data

6.Data Frames:Organizing values into data frames, loading frames from files and merging them

7.Working With Real-World Data:Testing for correlation between data sets, linear models and installing additional packages”*

You can earn badge like the one below if you complete tutorial.

Code school badge

And now fun part started – creating my own User case and visualization of the same.

After long research an idea was born to analyse dependency on Chocolate consumption & Unemployment. First I had to find data tables and create CSV file and load it into R.

Country Kg per Capita Unemployment %
Switzerland 9 4.3
Germany 7.9 5.3
Austria 7.8 4.9
Ireland 7.5 13.4
USA 7.5 7.3
Norway 6.6 3.5
Estonia 6 9.2
Slovakia 5.4 14.6
Sweden 5.4 8.2
Finland 5.3 8.6
Kazakhstan 5.3 5.5
Russia 5.3 5.8
Belgium 5.2 8.7
Australia 4.9 5.7
Netherlands 4.7 7.2
New Zealand 4.5 6.1
UK 4.3 7.2
Denmark 4.2 7
France 4.2 10.9
Lithuania 4.2 11.5

Once data was available in R I was able to plot 2 variables and create below graph.

Chocolate consumption vs Unemployment

After few hours spent discovering R possibilities I can confirm with certainty that new R follower was born…

*from “http://tryr.codeschool.com/”