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 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