#Given, exam_score = data.frame( ID = c(1, 2, 3, 4, 5 ), Name = c(“Alice”, “Bob”, “David”, “John”, “Jenny” ), Age = c(20, 25, 30, 22, 18 ), Score = c(100, 78, 90, 55, 81 ) ) #Data frame
exam_score = data.frame(
ID = c(1, 2, 3, 4, 5 ),
Name = c("Alice", "Bob", "David", "John", "Jenny" ),
Age = c(20, 25, 30, 22, 18 ),
Score = c(100, 78, 90, 55, 81 )
)
exam_score
#Row add
new_row = c(6, "Santo", 22, 80 )
exam_score = rbind(exam_score, new_row)
new_r = c(7,"Shakhawat", 23, 79 )
exam_score = rbind(exam_score, new_r)
exam_score
NA
#Column add
Income = c(70000, 80000, 90000, 100000, 60000, 10000,12000 )
exam_score = cbind(exam_score, Income)
exam_score
NA
#Max
Income = c(70000, 80000, 90000, 100000, 60000, 10000,12000 )
max(Income)
[1] 1e+05
Age = c(20, 25, 30, 22, 18, 22, 23 )
max(Age)
[1] 30
Score = c(100, 78, 90, 55, 81, 80, 79 )
max(Score)
[1] 100
#Min
min(Income)
[1] 10000
min(Age)
[1] 18
min(Score)
[1] 55
#Median
median(Age)
[1] 22
median(Score)
[1] 80
median(Income)
[1] 70000
#Sum
sum(Age)
[1] 160
sum(Score)
[1] 563
sum(Income)
[1] 422000
#Mean
mean(Age)
[1] 22.85714
mean(Score)
[1] 80.42857
mean(Income)
[1] 60285.71
#SD
sd(Age)
[1] 3.848314
sd(Score)
[1] 13.72172
sd(Income)
[1] 36063.44
#Variance
var(Age)
[1] 14.80952
var(Score)
[1] 188.2857
var(Income)
[1] 1300571429
#Quantiles
quantile(Age)
0% 25% 50% 75% 100%
18 21 22 24 30
quantile(Score)
0% 25% 50% 75% 100%
55.0 78.5 80.0 85.5 100.0
quantile(Income)
0% 25% 50% 75% 100%
10000 36000 70000 85000 100000
#Correlation #a
cor(Age, Score)
[1] 0.08341482
Weak positive correlation
#b
cor(Age,Income)
[1] 0.2765528
Weak positive correlation
#c
cor(Score,Income)
[1] -0.1659946
Weak negative correlation
#Select row,Score >= 80
exam_score[exam_score$Score >=80 | exam_score$Score == 100 , ]
#Select rows with the age range of 20 to 30
exam_score[ exam_score$Age >= 20 | exam_score$Age == 30 , ]
#Select rows with age 22,25 and 30
exam_score[ exam_score$Age == 22 | exam_score$Age == 25 | exam_score$Age == 30 , ]