A data frame is a two-dimensional array-like structure, or we can say it is a table in which each column contains the value of one variable, and row contains the set of value from each column.
Characteristics of a data frame:
- The column name will be non-empty.
- The row names will be unique.
- A data frame stored numeric, factor or character type data.
- Each column will contain same number of data items.
stud_id = c(1:10)
stud_Name = c('Ade Oluwa', 'Bala Baba', 'Kings Lawal', 'Paul Azige', 'Nzebe Jude', 'Olusegun Bolanle', 'Olu Henry', 'Prince Charlse', 'Harry Papa', 'Ben Ole')
stud_Name
## [1] "Ade Oluwa" "Bala Baba" "Kings Lawal" "Paul Azige"
## [5] "Nzebe Jude" "Olusegun Bolanle" "Olu Henry" "Prince Charlse"
## [9] "Harry Papa" "Ben Ole"
stud_CGPA = c(2.5, 4.6, 3.7, 4.5, 2.89, 4.45, 4.49, 5.0, 4.22, 2.7)
df = data.frame(stud_id, stud_Name, stud_CGPA)
typeof(stud_CGPA)
## [1] "double"
mean(stud_CGPA)
## [1] 3.905
print(df)
## stud_id stud_Name stud_CGPA
## 1 1 Ade Oluwa 2.50
## 2 2 Bala Baba 4.60
## 3 3 Kings Lawal 3.70
## 4 4 Paul Azige 4.50
## 5 5 Nzebe Jude 2.89
## 6 6 Olusegun Bolanle 4.45
## 7 7 Olu Henry 4.49
## 8 8 Prince Charlse 5.00
## 9 9 Harry Papa 4.22
## 10 10 Ben Ole 2.70
summary(df)
## stud_id stud_Name stud_CGPA
## Min. : 1.00 Length:10 Min. :2.500
## 1st Qu.: 3.25 Class :character 1st Qu.:3.092
## Median : 5.50 Mode :character Median :4.335
## Mean : 5.50 Mean :3.905
## 3rd Qu.: 7.75 3rd Qu.:4.497
## Max. :10.00 Max. :5.000