Lecture No.2 Introduction To R Language
Tayyab Rajput
comments :
Purpose of comments:
How to Create Better Comments?
Here we will discuss some example of comments:
# here we comment the code that will no be execute
x <- 3
y <- 4
#x+y
#my_name <- "Tayyab Rajput"
#my_name
Assignment 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
# Addition of two numbers
x <- 3
y <- 6
x+y
# Subtarction of two numbers
x <- 3
y <- 6
x-y
# Multiplication of two numbers
x <- 5
y <- 10
x*y
# Division of two numbers
x <- 10
y <- 5
x/y
# Exponent of number
x <- 6
y <- 1
x^y
# Modulus of the numbers
x <- 78
y <- 30
x%%y
# Intger division of numbers
x <- 23
y <- 6
x%/%y
Logical Operators :
# Performing operations on Operands
vec1=c(2,4,5)
vec2=c(4,5,6)
cat ("Vector1 less than Vector2 :", vec1 < vec2, "\n")
cat ("Vector1 less than equal to Vector2 :", vec1 <= vec2, "\n")
cat ("Vector1 greater than Vector2 :", vec1 > vec2, "\n")
cat ("Vector1 greater than equal to Vector2 :", vec1 >= vec2, "\n")
cat ("Vector1 not equal to Vector2 :", vec1 != vec2, "\n")
Vector1 less than Vector2 : TRUE TRUE TRUE Vector1 less than equal to Vector2 : TRUE TRUE TRUE Vector1 greater than Vector2 : FALSE FALSE FALSE Vector1 greater than equal to Vector2 : FALSE FALSE FALSE Vector1 not equal to Vector2 : TRUE TRUE TRUE
Print Function
my_name <-c("My name is tayyab")
print(my_name)
[1] "My name is tayyab"
# Addition of two numbers
x <- 10
y <- 45
print(x+y)
[1] 55
Check Your Concepts: