Lecture No.2 Introduction To R Language

Tayyab Rajput

Learning agenda of notebook:

  1. Use of comments
  2. Assignment Operator
  3. Arethmatic Operator
  4. Logical Operators
  5. Print() builtin Function

comments :


Comments are portions of a computer program that are used to describe a piece of code.
Comments have nothing to do with code logic. They do not get interpreted or compiled and are completely ignored during the execution of the program.


Purpose of comments:


Here are a few purposes of commenting on an R code:

  • It increases readability of the program for users other than the developers.
  • Comments in R provide metadata of the code or the overall project.
  • Comments are generally used by programmers to ignore some pieces of code during testing.
  • They are used to write a simple pseudo-code of the program.

  • How to Create Better Comments?


    You should always keep in mind the following points while writing comments.

  • Use Hash operator(#)
  • Use comments only to describe what a particular block of code does, not how it does.
  • Don't overuse comments. Try to make your code self-explanatory
  • Try to create comments that are as precise as possible.
  • Don't use redundant comments.
  • Here we will discuss some example of comments:

    Assignment operator:


    In R, the main and most used by R users is left-arrow operator ( <- ).

    Arehtmatic Operators :

    R has several operators to perform tasks including arithmetic, logical and bitwise operations. In this article, you will learn about different R operators with the help of examples. These operators are used to carry out mathematical operations like addition and multiplication. Here is a list of arithmetic operators available in R.

    Here we discuss some example of Arethmatic operators

    Logical Operators :


    Logical operators are used to carry out Boolean operations like AND, OR etc.

    Print Function


    In the R the print fuction is ued to print the output on the screen.
    Print output using paste() function inside print() function R provides a method paste() to print output with string and variable together. This method defined inside the print() function. paste() converts its arguments to character strings. One can also use paste0() method.
    The difference between paste() and paste0() is that the argument sep by default is ” “(paste) and “”(paste0).

    Check Your Concepts:

  • What are comments ?
  • Why we use comments ?
  • Perform the R script by using comments.
  • What is assignment operator ?
  • Assign the value 10 to X by using assignment operator
  • What are arehtmatic operators ?
  • Assign 10 to X and 5 to Y and perform all arehtmatic operator on them.
  • What are logical operator
  • Why we use logical operator
  • Take two numeric variables and perform logical operator on them.
  • What you know about print function .
  • Print your name on screen by using print function.