# R Programming

**1. What is R programming?**

**R** is a programming language and free software environment for statistical computing and graphics supported by the R Foundation for Statistical Computing. The R language is widely used among statisticians and data miners for developing statistical software and data analysis. Polls, data mining surveys, and studies of scholarly literature databases show substantial increases in popularity as of July 2020, R ranks 8th in the TIOBE index, a measure of popularity of programming languages.

**R** is a programming language and free software developed by Ross Ihaka and Robert Gentleman in 1993. R possesses an extensive catalog of statistical and graphical methods. It includes machine learning algorithms, linear regression, time series, statistical inference to name a few. Most of the R libraries are written in R, but for heavy computational tasks, C, C++ and Fortran codes are preferred.

**2. Why R programming?**

**1. R is important for Data Science**

R plays a very important role in Data Science, you will be benefited with following operations in R.

**You can run your code without any compiler**– R is an interpreted language. Hence we can run code without any compiler. R interprets the code and makes the development of code easier.**Many calculations done with vectors**– R is a vector language, so anyone can add functions to a single Vector without putting in a loop. Hence, R is powerful and faster than other languages.**Statistical Language**– R used in biology, genetics as well as in statistics. R is a turning complete language where any type of task can perform.

**2. R is good for Business**

R will just not help you in the technical fields, it will also be a great help in your business.

- Here, the major reason is that R is open-source, therefore it can be modified and redistributed as per the user’s need. It is great for visualization and has far more capabilities as compared to other tools.
- For data-driven businesses, lack of Data Scientists is a huge concern. Companies are using R programming as their core platform and are recruiting trained R programmers.

**3. R is a gateway to Lucrative Career**

R language is used extensively in Data Science. This field offers some of the highest-paying jobs in the world today. Data Scientists who are proficient in R make more than $117,000 (Rs 80,56,093) on an average per year. If you want to enter the field of Data Science and earn a lucrative salary, then you must definitely learn R.

**4. Open-source**

R is an open-source language. It is maintained by a community of active users and you can avail R for free. You can modify various functions in R and make your own packages. Since R is issued under the **General Public Licence (GNU)**, there are no restrictions on its usage.

**5. Popularity**

R has become one of the most popular programming languages in the industries. Conventionally, R was mostly used in academia but with the emergence of Data Science, the need for R in the industries became evident. R is used at Facebook for social network analysis. It is being used at Twitter for semantic analysis as well as visualizations.

**6. Robust Visualization Library**

R comprises of libraries like *ggplot2, *plotly that offer aesthetic graphical plots to its users. R is most widely recognized for its stunning visualizations which gives it an edge over other Data Science programming languages.

**7. With R, you can develop amazing Web-Apps**

R provides you with the ability to build aesthetic web-applications. Using the **R Shiny** package, you can develop interactive dashboards straight from the console of your R IDE. Using this, you can embed your visualizations and enhance the storytelling of your data analysis through aesthetic visualizations.

**8. R enjoys a vast Community Support**

R Programming is supported by a vast community that maintains and updates R. If you face any trouble with the code in R, you can avail the support of the community on places like Stack Overflow *(of course you can also ask us any queries in the comment section below, DataFlair is always there for you!)*. There are several communities around the world that organize **bootcamps**and **R meetups**.

**9. A go-to language for Statistics and Data Science**

R is the standard language for Statistics and Data Science. R was developed for statistics, by statisticians. It has been in use even before the word **“Data Science”** was coined. Statisticians and Data Scientists are most familiar with R than any other programming language. R facilitates various statistical operations through its thousands of packages.

**10. R is being used in almost every industry**

R is one of the most widely used programming languages in the world today. It is used in almost every industry, ranging from finance, banking to medicine and manufacturing. R is used for *portfolio management, risk analytics in finance and banking industries.* It is used for carrying out an analysis of drug discovery and genomic analysis in bioinformatics. R is also used to implement various statistical measures to optimize industrial processes.

**3. How to prepare?**

**Step 1: The Set-Up**

Before you can actually start working in R, you need to download a copy of it on your local computer. R is continuously evolving and different versions have been released since R was born in 1993 with (funny) names such as World-Famous Astronaut and Wooden Christmas-Tree. Installing R is pretty straightforward and there are binaries available for Linux, Mac and Windows from the Comprehensive R Archive Network (CRAN).

Once R is installed, you should consider installing one of R’s integrated development environment as well (although you could also work with the basic R console if you prefer). Two fairly established IDE’s are RStudio and Architect. In case you prefer a graphical user interface, you should check out R-commander.

**Step 2: Understanding the R Syntax**

Learning the syntax of a programming language like R is very similar to the way you would learn a natural language like French or Spanish: by practice & by doing. One of the best ways to learn R by doing is through the following (online) tutorials:

- DataCamp’s free introduction to R tutorial and the follow-up course Intermediate R programming. These courses teach you R programming and data science interactively, at your own pace, in the comfort of your browser.
- The swirl package, a package with offline interactive R coding exercises. There is also an online version available that requires no set-up.
- On edX you can take Introduction to R Programming by Microsoft.
- The R Programming course by Johns Hopkins on Coursera.

**Syllabus:**

**COURSE SYLLABUS**

Module 1 – R basics

- Math, Variables, and Strings
- Vectors and Factors
- Vector operations

Module 2 – Data structures in R

- Arrays & Matrices
- Lists
- Data frames

Module 3 – R programming fundamentals

- Conditions and loops
- Functions in R
- Objects and Classes
- Debugging

Module 4 – Working with data in R

- Reading CSV and Excel Files
- Reading text files
- Writing and saving data objects to file in R

Module 5 – Strings and Dates in R

- String operations in R
- Regular Expressions
- Dates in R

**4. Important materials:**

**a. E-books:**

1. R for Data Science by Hadley Wickham

2. Introduction to Data Science, R. Irizarry

3. Advanced R by Hadley Wickham

4. R Packages by Hadley Wickham

**b. Videos:**

**R programming tutorials for beginners:**

**R programming preparation:**

**R programming tutorials:**

**5. Sample test papers with answers:**

R programming sample question paper1:

https://www.sanfoundry.com/r-programming-questions-answers-data-types/

**6. Certifications on R programming:**

**1. R Programming Course A-Z™: R for Data Science With Real Exercises**

This is one of the best R programming tutorials that help you master programming in R and R studio with live examples. You will learn data analytics, data science, statistical analysis, packages, functions, GGPlot2.

More than 96,000 students have taken this Udemy R course. The course does not assume any prior knowledge or experience. It is designed in such a way that you can succeed at it even without any statistical background. It takes you step-by-step through the steep learning curve of R. You will be using specifically designed datasets to practice the skills you learn in the course.

The course begins with teaching R programming basics and how to combine programming and statistical concepts. Then the course progresses to advanced topics like matrices and data frames. All the course material is intertwined with ample of theory and real life examples to support learning. You will learn a new valuable skill in every single tutorial and in every section you will understand how you can apply that skill to solve real world problems.

Key Highlights

- Create visualizations to best capture your analysis and captivate your audience
- Learn to solve real life analytical challenges
- Learn how to customize R studio to suit your preferences
- Learn how to create and use vectors and matrices in R
- Learn how to install packages in R
- Practice working with financial, statistical and sports data in R
- Know all about Normal distribution and Law of Large Numbers
- Homework exercises for extra practice

**6. Important tips on R programming:**

**1. Writing Codes for Programmer, Developer, and Even for Layman**

Though codes are primarily written for the machine to understand. They should be structured and well organized for other developers or for any layman to understand. In reality, codes should be written for all the three.

**2. Knowing how to Improve**

R has multiple ways to achieve a task. Each of the possibilities comes from using more memory, faster execution or different algorithm/logic.

Whenever possible, good programmers make this choice wisely.

R has the feature to execute code in parallel. Lengthy tasks such as fitting models can be executed in parallel, resulting in time-saving. Other tasks can also be executed faster based on the logic and packages used.

**3. Writing Robust Code**

While writing code, you can make the code simple but situation specific or write a generic code. One such way in which programmers write simple but situation-specific code is by **‘Hard Coding’.**

It is the term given to fixing values of variables and is never recommended.

For example, dividing the sum of all salaries in a 50,000-row salary data by 50,000 rather than dividing the sum of that sum with the number of rows may seem to make the same sense but have a different meaning in programming.

**4. When to Use Shortcuts and When Not to**

Using shortcuts may be tempting in the pursuit of writing code swiftly but the right practice is to know when to use them.

For instance, shortcut keys are something which is really helpful and can always be used. Using **Ctrl+L** in windows clears the console output screen, Using **Ctrl+Shift+C** in windows comments and un-comments all selected lines of code in one go are my favorite shortcuts in Rstudio.

**5. Reduce Effort Through Code Reuse**

When you start writing a code, you don’t need to waste time if a particular piece of logic has already been written for you. Better known as **“Code Re-use”,** you can always use your own code you previously wrote or even google to reach out the large R community.