Data input

ID = c(1, 2, 3, 4, 5, 6, 7)
  Name = c("Alice", "Bob", "David", "John", "Jenny", "Mike", "James")
  Age = c(20, 25, 30, 22, 18, 21, 31)
  Score = c(100, 78, 90, 55, 81, 65, 80)

Data Frame

exam_score = data.frame(
  ID = c(1, 2, 3, 4, 5, 6, 7),
  Name = c("Alice", "Bob", "David", "John", "Jenny", "Mike", "James"),
  Age = c(20, 25, 30, 22, 18, 21, 27),
  Score = c(100, 78, 90, 55, 81, 65, 80)
)
exam_score
##   ID  Name Age Score
## 1  1 Alice  20   100
## 2  2   Bob  25    78
## 3  3 David  30    90
## 4  4  John  22    55
## 5  5 Jenny  18    81
## 6  6  Mike  21    65
## 7  7 James  27    80

Adding a new colum

 Income = c(3500, 2800, 3200, 2200, 3100, 2500, 3000)
exam_score= cbind(exam_score, Income)
exam_score
##   ID  Name Age Score Income
## 1  1 Alice  20   100   3500
## 2  2   Bob  25    78   2800
## 3  3 David  30    90   3200
## 4  4  John  22    55   2200
## 5  5 Jenny  18    81   3100
## 6  6  Mike  21    65   2500
## 7  7 James  27    80   3000

Finding max, min, median, sum, mean, standard deviation, variance, and quantiles of columns Age, Score, and Income

max(Age)
## [1] 31
min(Age)
## [1] 18
median(Age)
## [1] 22
sum(Age)
## [1] 167
mean(Age)
## [1] 23.85714
sd(Age)
## [1] 5.014265
var(Age)
## [1] 25.14286
quantile(Age)
##   0%  25%  50%  75% 100% 
## 18.0 20.5 22.0 27.5 31.0
max(Score)
## [1] 100
min(Score)
## [1] 55
median(Score)
## [1] 80
sum(Score)
## [1] 549
mean(Score)
## [1] 78.42857
sd(Score)
## [1] 14.93159
var(Score)
## [1] 222.9524
quantile(Score)
##    0%   25%   50%   75%  100% 
##  55.0  71.5  80.0  85.5 100.0
max(Income)
## [1] 3500
min(Income)
## [1] 2200
median(Income)
## [1] 3000
sum(Income)
## [1] 20300
mean(Income)
## [1] 2900
sd(Income)
## [1] 439.6969
var(Income)
## [1] 193333.3
quantile(Income)
##   0%  25%  50%  75% 100% 
## 2200 2650 3000 3150 3500

Finding Correlations

cor (Age, Score)
## [1] 0.1456474
cor(Age, Income)
## [1] 0.1058318
cor(Score, Income)
## [1] 0.9875041

Score greater or equal 80

exam_score[exam_score$Score >=80 , ]
##   ID  Name Age Score Income
## 1  1 Alice  20   100   3500
## 3  3 David  30    90   3200
## 5  5 Jenny  18    81   3100
## 7  7 James  27    80   3000

Age in the range of 20 to 30

exam_score [exam_score$Age >= 20  & Age <= 30, ]
##   ID  Name Age Score Income
## 1  1 Alice  20   100   3500
## 2  2   Bob  25    78   2800
## 3  3 David  30    90   3200
## 4  4  John  22    55   2200
## 6  6  Mike  21    65   2500