If you’ve used JavaScript or other scripting languages, you’re going to love using R. This free, open source language is fully functional, with 25 years of history, so if you haven’t yet given it a try, now is a good time to start. Here are 5 compelling reasons why you should jump in and start using R today!

1. Benefit from full documentation and support

Online resources for R—including message boards—are well supported and well documented. Several important R developers actively participate in the online discussion of the tools and packages they designed. This is important because R programming includes a lot of community packages, from packages used to parse JSON and XML files, to packages to help create Random-Effects regression models.

The functionality of R can sometimes seem endless due to the diligent work of the R community of developers. The great documentation and participation from R developers makes it more accessible to people who are just starting out.

2. Make yourself more appealing to employers

Employers see R as an inherently useful and valuable skill. This is especially true in any industry that relies on data analysis. The prices of the popular statistical packages, especially at the enterprise level, are very high. Many employers understand that if they hire people who can use R, they can save thousands by not having to purchase proprietary statistics packages. So, set yourself apart and learn R. It might just get you hired.

3. Acquire, clean, and analyze your data in one place

By using R, you can do your data acquisition, cleaning, and analysis all in one place. Let’s have a look at a simple example of what this means.

Listing 1 shows a script that loads necessary libraries. Lines 4 through 14 perform a GET request to an NFL statistics site, and then parse the JSON response. After performing a few more formating niceties, the data is loaded into a dataframe and is ready for analysis (lines 15-16).

Listing 1. A simple example

library(httr)

library(xml2)

library(mongolite)

resp <- GET('http://www.nfl.com/stats/categorystats?tabSeq=

1&statisticPositionCategory=RUNNING_BACK&season=2016&seasonType=REG')

nfltext <- content(resp,as="text")

rad <- read_html(nfltext)

trs <- xml_find_all(rad, ".//tr")

colNames <- xml_text(xml_children(trs[1]),trim = T)

mat <- matrix(nrow = length(trs) - 1,ncol = length(colNames))

for(i in 2:length(trs)){
  
    child <- xml_children(trs[i])
  
    mat[i-1,]<- xml_text(child,trim=T)

}

df <- data.frame(mat)

colnames(df) <- colNames

 

The following script takes it a step further. This code creates a new database in a running local Mongo instance and inserts the dataframe containing the desired NFL statistics. The script then outputs some information, verifying that the data was properly put into the database. Any scripting language can perform these tasks, but look at how R keeps it clean and easy.

 

running_backs = mongo(collection = "2016RunningBacks", db = "NFLPlayers")

running_backs$insert(df)

running_backs$count()

running_backs$iterate()$one()

 

When you move into a data analysis phase, you’ll have many of the necessary tools at your fingertips.

The script in Listing 2 shows some data analysis of the football data.

Listing 2. Football data analysis

library(mongolite)

running_backs = mongo(collection = "2016RunningBacks", db = "NFLPlayers")

df <- running_backs$find(fields='{"_id":0,"Att":1,"Att/G":1,
                         
                            "Yds":1,"Yds/G":1,"TD":1,"1st":1,"FUM":1}')

df[1:7] <- apply(df[,1:7],1,function(x){gsub(",","",x)})

df[1:7] <- apply(df[,1:7],1,as.numeric)

nfl.pc <- prcomp(df,center = TRUE,scale. = TRUE)

print(nfl.pc)

summary(nfl.pc)

plot(nfl.pc, type = "l")

 

Here you reload the mongolite library to pull in the data just added to the database. The data came in as strings, but as you can see in the script, R’s APPLY function can quickly perform large scale changes to dataframes, such as changing characters to numerics. The rest of the script performs basic principle component analysis to see how these statistics can be generalized or combined into indices, as shown in Figure 1.

Sophisticated data analysis
Figure 1. Sophisticated data analysis

The plot shows that this group of variables doesn’t seem to have an underlying factor, or factors. This is certainly not groundbreaking, but it is sophisticated data analysis right in the same place where the data was acquired and cleaned. By learning R, you get the best of both the data analysis and general scripting worlds.

4. Take advantage of R’s excellent data visualization potential

R’s data visualization tools are great. The script in Listing 3 performs some data analysis on football data.

Listing 3. Further football data analysis

library(ggplot2)

lmod <- lm(`Yds/G`~`FUM`,data=df)

par(mfrow=c(2,2))

plot(lmod)

par(mfrow=c(1,1)

ggplot(df,aes(x=`Yds/G`,y=`TD`))+
  
  geom_point(aes(size = `1st`))+
  
  geom_smooth()+
  
  labs(x = "Yards per Game",y ="Touchdowns",title = "Yards per Game

and Touchdowns")

 

First, a linear model is stored in the lmod object. This model measures a relationship between yards per game and number of fumbles for the running backs in the dataset. In order to get the diagnostic plots from this linear model, just call the plot function on the lmod object. This is a huge time saver when you’re just interested in a quick glance at whether or not a linear model is appropriate for the data you’re working with.

The plots produced by this function are shown in Figure 2.

Diagnostic plots
Figure 2. Diagnostic plots

The next function call is that of ggplot. The package ggplot2 creates publication quality data visualizations with relative ease. The plot that is created by the functional call is shown in Figure 3.

 
ggplot2 graph
Figure 3. – A ggplot2 result

This plot does a good job of displaying the complex relationship between yards per game and touchdowns, as well as first downs. This may not be a great discovery, but the quality of the graphs produced by ggplot is excellent.

5. Get up to speed quickly

R is easy to learn. There is plenty of online community help available, and even companies offering high quality online courses. One reason R is so intuitive is that it wasn’t created for computer scientists. It was created for mathematicians, so the way the language is organized might be easier for some non-programmers to grasp.

The script in Listing 4 shows the language’s simplicity, with the results shown in Figure 4.

The script in Listing 4 creates three random samples and then creates a bar graph of the data. The sample function is called “sample” because you’re making a sample, and the probabilities are set using the prob option. data.frame refers to how the data is held.

Listing 4. Simplicity of R

library(ggplot2)

ydata <- sample(c(1:100),10000,replace=T)

xdata <- sample(c("Erik","Cooper","Stewart"),10000,replace = T)

zdata <- sample(c("Red","Blue","Green","Yellow","Orange"),10000,replace = 
T,prob=c(0.4,0.2,0.25,0.1,0.05))

df <- data.frame(Marbles=ydata,Person=xdata,Color=zdata)

ggplot(df,aes(x=Person,fill=Color))+
  
    geom_bar(position="dodge")+
  
    scale_fill_manual(values=c("light blue","light 
green","#ff8000","#ff3232","#ffff66"))+
  
    labs(fill="Ball Color")

The graph works by setting a base and then adding elements on top. These elements have intuitive names like geom_bar for bar graphs and the resulting graph looks pretty good for the amount of effort required to create it.

balls
Figure 4. Three random samples

Learning any language is difficult, but R is easier than most.

Summary

From helpful documentation to powerful data visualization tools, these are just some of the great reasons why you should use R. And expect more improvements and tools from the active R community in the future. Are you ready? Dive in and discover how great the R programming language is!

Resources

3 comments on"5 reasons you should learn R programming language now"

  1. you didn’t escape the < in your code snippets…

  2. Convincing reasons for learning R programming language…Find out basic features and other details of R Programming at https://www.nikkisblog.com/p/r-programming-language-introduction-to.html

Join The Discussion

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