Basic Introduction To R Programming Language

VICTOR OMONDI
May 16, 2020 · 4 min read
Image for post
Image for post
Poster: Basic Introduction To R

In this article we will cover the intro basics to R Programming Language. This article is meant for people willing to start programming in R, beginners in R who are willing to expand their already gained knowledge in R, or people willing to start their Data Science journey using R programming language. If you are familiar with other programming languages, getting to understand R programming language will be as easy as drinking water.

Image for post
Image for post
Poster: Goal

What is R?

According to Wikipedia: 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.

R language provides a wide variety of statistical (linear and nonlinear modelling, classical statistical tests, time-series analysis, classification, clustering, …) and graphical techniques, and is highly extensible. READ MORE>>

How to Install and Getting Started With R

Once you have R and Rstudio installed, let’s proceed to the business of the Day.

Intro To R Basics

Hello, World!

print prints its argument and returns it invisibly

In order to print Hello, World! in R, you need to pass the string "Hello, World!" in the print() function. the strings can be in double quotes "" or single quotes ''.

Using Print Function to Print “Hello, World!”

The output will be as follows:

[1] "Hello, World!"

Creating and Naming Variables

Rules for Naming Variables in R

unlike other languages, Underscore(_) at the beginning of the variable name are NOT allowed in R

  • Keywords CANNOT be used to name variables
  • Special Character like #, or & and whitespace eg tab or space CANNOT be used in variable names
  • Variable names are Case Sensitive, therefore, my_name is different from my_Name.

Below are examples of correct variable names and assignment in R:

Various Types of naming a variable

Their output are as follows:

[1] 17
[1] "Victor"
[1] 17347.38

R Arithmetic Operators

R Arithmetic Operators and their functions

Let us use R arithmetic operators to calculate my age. We will use the already gained knowledge of variables and arithmetic operations we’ve discussed above.

Using R Arithmetic Operators to perform calculations
[1] 19

As you can see age is a variable that stores the computations done when subtracting year_of_birth from current_year.

Comments in R

Comments in R
[1] 19

Basic Data Types in R

Data type is the classification/categorization of data item. Everything in python is an object therefore, data types are classes and variables are the instance (object) of the data type. Use class(variable_name) in order to understand to which data type a variable belongs.

To get you started with R Basic Data types, note the following:

  • Decimal values are called numerics
  • Natural Numbers are called Integers, Integers are also numerics
  • Boolean values, eg( FALSE or TRUE) are called logical. R is case sensitive, logicals must be in UPPERCASE
  • String values/text values are called characters
[1] "numeric"
[1] "numeric"
[1] "character"
[1] "logical"

More Resources

  • Introduction to R Online Course | DataCamp: link

And that marks the end of this article, keep an eye for more R articles as I cover more of R programming language to get you started in Data Science with R. Have any question? Ask Me on the comments.

References

Image for post
Image for post
Poster: Thank you

The Startup

Medium's largest active publication, followed by +755K people. Follow to join our community.

VICTOR OMONDI

Written by

Data Scientist |@AgoraIO, @Ingressive, @MoringaSchool & CodeLn Campus Ambassador | @DSC_MMU Lead | @CITClubMMU Ass.Chairman| Mentor @Technovation & @AndelaALC

The Startup

Medium's largest active publication, followed by +755K people. Follow to join our community.

VICTOR OMONDI

Written by

Data Scientist |@AgoraIO, @Ingressive, @MoringaSchool & CodeLn Campus Ambassador | @DSC_MMU Lead | @CITClubMMU Ass.Chairman| Mentor @Technovation & @AndelaALC

The Startup

Medium's largest active publication, followed by +755K people. Follow to join our community.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store