Lab 1 Saeed
Lab 1 Saeed
Lab 1 Saeed
Submitted By:
Name: Saeed Ahmad Awan
Subject: Probability and Statistics
Department: Data Science
Semester: 3rd
Submitted To:
Lecturer: Dr. Ammad Khalil
R Programming Language Features
Statistical Features of R
Basic Statistics: The most common basic statistics terms are the average, the mode, and the median. These are all known as
"central tendency measures." R makes it easy to measure central tendency.
Static Graphics: R has many features for creating and developing interesting static graphics. It includes functionality for many
plot types, including geographic maps, mosaic plots, and biplots.
Probability Distributions: Probability distributions play a vital role in statistics, and R makes it easy to handle various types of
probability distributions, such as the binomial distribution, the normal distribution, and the chi-squared distribution.
Data Analysis: R provides a large, coherent, and integrated collection of tools for data analysis.
Advantages of R
Comprehensive Statistical Analysis Package: R is the most comprehensive statistical analysis package available. New
technologies and concepts often appear first in R.
Open Source: R is an open-source programming language, so you can run it anywhere and anytime.
Cross-Platform: R is suitable for Linux and Windows operating systems and runs on any operating system.
Collaborative Development: Everyone is welcome to contribute new packages, bug fixes, and code enhancements to R.
Disadvantages of R
Applications of R
Data Science: R is used for data science, and it provides a wide variety of libraries related to statistics. It also provides an
environment for statistical computing and design.
Quantitative Analysis: R is used by many quantitative analysts as a programming tool. It is useful for data importing and
cleaning.
Finance: R is the most prevalent language used by data analysts and research programmers. Therefore, it is used as a
fundamental tool for finance.
Industry: Tech giants like Google, Facebook, Bing, Twitter, Accenture, and Wipro use R.
Basics of R
R Print Output
print("Hello World!")
Loops
And there are times you must use the print() function to output code, for example when working
with for loops
for (x in 1:10) {
print(x)
}
Comments
Comments can be used to explain R code, and to make it more readable. It can also be used to
prevent execution when testing alternative code.
Comments starts with a #. When executing code, R will ignore anything that starts with #.
"Hello World!" # This is a comment
Creating Variables in R
name <- "Ali"
age <- 40
Concatenate Elements
You can also concatenate, or join, two or more elements, by using the paste() function.
To combine both text and a variable, R uses comma (,):
text1 <- "R is"
text2 <- "awesome"
paste(text1, text2)
Addition
a <- c (1, 0.1)
b <- c (2.33, 4)
print (a+b)
Subtraction
a <- 6
b <- 8.4
print (a-b)
Multiplication
B= c(4,4)
C= c(5,5)
print (B*C)
Division
a <- 10
b <- 5
print (a/b)
Modulo Operation
list1<- c(2, 22)
list2<-c(2,4)
print(list1 %% list2)
# R program to illustrate
# the use of Arithmetic operators
vec1 <- c(0, 2)
vec2 <- c(2, 3)
# Performing operations on Operands
cat ("Addition of vectors :", vec1 + vec2, "\n")
cat ("Subtraction of vectors :", vec1 - vec2, "\n")
cat ("Multiplication of vectors :", vec1 * vec2, "\n")
cat ("Division of vectors :", vec1 / vec2, "\n")
cat ("Modulo of vectors :", vec1 %% vec2, "\n")
cat ("Power operator :", vec1 ^ vec2)
Apply all the above basics on it.
#R Print Output
print("Hello World!")
for (x in 1:10) {
print(x)
}
#Creating Variables in R
name <- "Ali"
age <- 40
text1 <- "R is"
text2 <- "awesome"
paste(text1, text2)
#Addition
a <- c (1, 0.1)
b <- c (2.33, 4)
print (a+b)
#Subtraction
a <- 6
b <- 8.4
print (a-b)
#Multiplication
B= c(4,4)
C= c(5,5)
print (B*C)
#Division
a <- 10
b <- 5
print (a/b)
#Modulo Operation
list1<- c(2, 22)
list2<-c(2,4)
print(list1 %% list2)
# R program to illustrate
# the use of Arithmetic operators
vec1 <- c(0, 2)
vec2 <- c(2, 3)
# Performing operations on Operands
cat ("Addition of vectors :", vec1 + vec2, "\n")
cat ("Subtraction of vectors :", vec1 - vec2, "\n")
cat ("Multiplication of vectors :", vec1 * vec2, "\n")
cat ("Division of vectors :", vec1 / vec2, "\n")
cat ("Modulo of vectors :", vec1 %% vec2, "\n")
cat ("Power operator :", vec1 ^ vec2)
OUTPUT
# Basic arithmetic operations
2+3
14 / 6
14 / 6 + 5
14 / (6 + 5)
OUTPUT
Question 2
Part a
Part b
Part c
Part d
log10(0.3)
Output
[1] -0.5228787
Querstion 3
Part a, b,c