R Programming: Statistics For Engineers - L4+L5+L6
R Programming: Statistics For Engineers - L4+L5+L6
S. Devi Yamini
1 Syllabus
1 Syllabus
2 Evaluation Rubrics
1 Syllabus
2 Evaluation Rubrics
3 Introduction to R
1 Syllabus
2 Evaluation Rubrics
3 Introduction to R
4 Basics
1 Syllabus
2 Evaluation Rubrics
3 Introduction to R
4 Basics
5 Data types
1 Syllabus
2 Evaluation Rubrics
3 Introduction to R
4 Basics
5 Data types
6 Data Structures
1 Syllabus
2 Evaluation Rubrics
3 Introduction to R
4 Basics
5 Data types
6 Data Structures
1 Syllabus
2 Evaluation Rubrics
3 Introduction to R
4 Basics
5 Data types
6 Data Structures
Criteria Marks
10 labs (each lab submission carries 5 marks) 50 marks
10 labs (assessment in each lab carries 5 marks) 50 marks
Mid sem 20 marks
Total marks for internals 120
Criteria Marks
10 labs (each lab submission carries 5 marks) 50 marks
10 labs (assessment in each lab carries 5 marks) 50 marks
Mid sem 20 marks
Total marks for internals 120
Criteria Weightage
Internals 60%
FAT 40%
Total 100%
1 Syllabus
2 Evaluation Rubrics
3 Introduction to R
4 Basics
5 Data types
6 Data Structures
1 Syllabus
2 Evaluation Rubrics
3 Introduction to R
4 Basics
5 Data types
6 Data Structures
Aim
Understanding basic concepts in R, Data types, importing/exporting data
Aim
Understanding basic concepts in R, Data types, importing/exporting data
Try these!!
4+7
Aim
Understanding basic concepts in R, Data types, importing/exporting data
Try these!!
4+7
52
Aim
Understanding basic concepts in R, Data types, importing/exporting data
Try these!!
4+7
52
4+2∗4
Aim
Understanding basic concepts in R, Data types, importing/exporting data
Try these!!
4+7
52
4+2∗4
8/2
Aim
Understanding basic concepts in R, Data types, importing/exporting data
Try these!!
4+7
52
4+2∗4
8/2
7%%2
Aim
Understanding basic concepts in R, Data types, importing/exporting data
Try these!!
4+7
52
4+2∗4
8/2
7%%2
5.5%/%3
Aim
Understanding basic concepts in R, Data types, importing/exporting data
Try these!!
4+7
52
4+2∗4
8/2
7%%2
5.5%/%3
5 > 2, 5 < 2, 5 == 2, 5 <= 2,5 >= 2, 5! = 2
Assignment
Example
x = 20
x < −20
20− > x
x = x + 10
Assignment
Example
x = 20
x < −20
20− > x
x = x + 10
Built-in functions
Example
log (10)
log 10(10)
sin(1)
atan(1)
sqrt(2)
pi
1 Syllabus
2 Evaluation Rubrics
3 Introduction to R
4 Basics
5 Data types
6 Data Structures
Logical
Example
v=TRUE
class(v)
(or) typeof(v)
Output: “logical”
Logical
Example
v=TRUE
class(v)
(or) typeof(v)
Output: “logical”
Example
v=16.5
class(v)
Output: “numeric”
Integer
Example
v=as.integer(4)
class(v)
Output: “integer”
Integer
Example
v=as.integer(4)
class(v)
Output: “integer”
Complex
Example
v=3+2i
class(v)
Output: “complex”
Character
Example
v=“TRUE”
print(class(v))
Output: “character”
Character
Example
v=“TRUE”
print(class(v))
Output: “character”
paste(“First”,“Second”,“Third”)
paste(“First”,“Second”,“Third”,sep=“:”)
(or) Fname=“Nathan”
Lname=“Muthuswamy”
paste(Fname,Lname,sep=“:”)
1 Syllabus
2 Evaluation Rubrics
3 Introduction to R
4 Basics
5 Data types
6 Data Structures
Example
a=c(“red”,“green”,“yellow”)
a
x=c(1,2,3)
x
length(x)
Example
a=c(“red”,“green”,“yellow”)
a
x=c(1,2,3)
x
length(x)
Example
li=list(2,3,4,”a”,21.2,”b”,sin)
li
Example
M=matrix(c(1,2,3,4,5,6),nrow=2,ncol=3,byrow=TRUE)
M
Example
M=matrix(c(1,2,3,4,5,6),nrow=2,ncol=3,byrow=TRUE)
M
Arrays (Unlike matrices, arrays can be of any number of dimensions)
Example
a=array(c(”G”,”Y”),dim=c(3,3,2))
a
Factors (It stores the vector along with the distinct values of the
elements in the vector as labels)
Example
cols=c(“green”,“green”,“yellow”,“red”,“red”,“red”,“green”)
faccols=factor(cols)
Factors (It stores the vector along with the distinct values of the
elements in the vector as labels)
Example
cols=c(“green”,“green”,“yellow”,“red”,“red”,“red”,“green”)
faccols=factor(cols)
Example
d=data.frame(id=c(’a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’,’i’,’j’),x=1:10, y=11:20)
d
b=data.frame(gender=c(“Male”,“Male”,“Female”),
height=c(152,171.5,165), weight=c(81,93,78), age=c(42,38,26))
b
Example
v = c(2, 5.5, 6)
t = c(8, 3, 4)
v + t; v − t; v ∗ t; v /t
v %%t;
v > t; v < t; v == t; v ! = t
Example
v = c(2, 5.5, 6)
t = c(8, 3, 4)
v + t; v − t; v ∗ t; v /t
v %%t;
v > t; v < t; v == t; v ! = t
Example
mtcars - Built-in data frame in R
mtcars[1, 2]
nrow (mtcars)
ncol(mtcars)
head(mtcars)
Enter the following data in Excel sheet and save it as CSV file.