#a.(i)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
new_row = c("6", "shihar", "26", "95")
exam_score = rbind(exam_score, new_row)
exam_score
new_row = c("7", "sara", "25", "97")
exam_score = rbind(exam_score, new_row)
exam_score
###a.(iii) Add column
Income = c(10000, 20000, 30000, 40000, 50000, 60000 , 60000)
exam_score = cbind(exam_score,Income)
exam_score
###b(i).age
age = c(20, 25, 30, 22, 18, 26, 25)
max(age)
## [1] 30
min(age)
## [1] 18
median(age)
## [1] 25
sum(age)
## [1] 166
mean(age)
## [1] 23.71429
sd(age)
## [1] 4.029652
var(age)
## [1] 16.2381
quantile(age)
## 0% 25% 50% 75% 100%
## 18.0 21.0 25.0 25.5 30.0
score = c(100, 78, 90, 55, 81, 95, 97)
max(score)
## [1] 100
min(score)
## [1] 55
median(score)
## [1] 90
sum(score)
## [1] 596
mean(score)
## [1] 85.14286
sd(score)
## [1] 15.59304
var(score)
## [1] 243.1429
quantile(score)
## 0% 25% 50% 75% 100%
## 55.0 79.5 90.0 96.0 100.0
###b(iii).Income
Income = c(10000, 20000, 30000, 40000, 50000, 60000 , 60000)
max(Income)
## [1] 60000
min(Income)
## [1] 10000
median(Income)
## [1] 40000
sum(Income)
## [1] 270000
mean(Income)
## [1] 38571.43
sd(Income)
## [1] 19518
var(Income)
## [1] 380952381
quantile(Income)
## 0% 25% 50% 75% 100%
## 10000 25000 40000 55000 60000
###C.Correlation ##(i)Age and score
cor(age, score)
## [1] 0.210303
##(ii) Age and Income
cor(age, Income)
## [1] 0.07870842
cor(score, Income)
## [1] 0.02268729
exam_score[exam_score$score >=80,]
###e.Select rows with the age range of 20 to 30.
exam_score[exam_score$age>=20, ]