maxwizard01
Posted on April 18, 2021
Tabular
🔥 Introduction to R (1)
🔥 Data Structure (2)
🔥 Statistical value (mean, median, mode etc) (3)
🔥 Tabular Presentation of Data (4)
🔥 Ploting graph with R
🔥 constructing frequency distribution with R (6)
There are three important method of presenting data one of them is table method. most of us are use to table presentation before but how do we tabulate our data using R-programming??
I can guarrantee you this is the most simplest method of presenting data and the commonest one. let's quicly take a look at some examples
Example1
let's say we need to draw a table for 5 Students in University of Ibadan with some bio-data like below:
Name | Level | MatricNumber | Faculty | Department |
---|---|---|---|---|
Oladejo Abdullahi | 100level | 221382 | Education | Mathematics |
Olasupo Tomiwa | 100level | 22452 | Science | Biology |
Adeniran Grace | 300level | 222138 | Education | Economics |
Ogunola Iretioluwa | 200level | 223482 | Science | chemistry |
Enabulele blessing | 300level | 229982 | Sceince | Mathematics |
Now we need to draw the same table above using R-programming so how can we do that?? it is just a simple logic. we make use of a function called data.frame()
. this function will arrange the data the way we want. let us write code for example 1
Codes
Name=c("Oladejo Abdullahi","Olasupo Tomiwa","Adeniran Grace","Ogunola Iretioluwa","Enabulele blessing")
Level=c("100level","100level","300level","200level","300level")
MatricNumber=c(221382,22452,222138,223482,229982)
Faculty=c("Education","Science","Education","Science","Science")
Department=c("Mathematics","Biology","Economics","Chemistry","Mathematics")
table=data.frame(Name,Level,MatricNumber,Faculty,Department)
print(table)
Result>>
>Name=c("Olasupo Tomiwa","Adeniran Grace","Ogunola Iretioluwa","Enabulele blessing")
> Level=c("100level","100level","300level","200level","300level")
> MatricNumber=c(221382,22452,222138,223482,229982)
> Faculty=c("Education","Science","Education","Science","Science")
> Department=c("Mathematics","Biology","Economics","Chemistry","Mathematics")
> table=data.frame(Name,Level,MatricNumber,Faculty,Department)
> table
Name Level MatricNumber Faculty Department
1 Oladejo Abdullahi 100level 221382 Education Mathematics
2 Olasupo Tomiwa 100level 22452 Science Biology
3 Adeniran Grace 300level 222138 Education Economics
4 Ogunola Iretioluwa 200level 223482 Science Chemistry
5 Enabulele blessing 300level 229982 Science Mathematics
>
study the code and the result it is very easy just write each of the data in a vector then write all of the vector inside the frame that is all.
one of the most important table in statistics is frequency table let us do one example on that.
How to use R to construct frequency table
we all know that fequency table is usually divided in to two
- the class mark
- the frequecy let us quiclky take a look at example.
Example2
use the R programming to construct the following frequency table.
Mark | Frequency |
---|---|
50 | 4 |
60 | 6 |
70 | 10 |
75 | 5 |
80 | 9 |
Solution
To write the code for the table we need to assign frequency and mark vectors then put them in to data frame.
codes>>
Mark=c(50,60,70,75,80)
Frequency=c(4,6,10,5,9)
freqTable=data.frame(Mark,Frequency)
freqTable
Result>>
> Mark=c(50,60,70,75,80)
> Frequency=c(4,6,10,5,9)
> freqTable=data.frame(Mark,Frequency)
> freqTable
Mark Frequency
1 50 4
2 60 6
3 70 10
4 75 5
5 80 9
>
Now before we stop let's try to construct a table using class interval when we are grouping data.
Example3
draw a frequency table for the height of 50 man using the class width of 5.
21,40,33,40,33,40,33,22,34,36,
26,27,22,26,27,34,38,26,27,27,
27,40,33,40,26,27,22,26,26,27,
34,38,26,27,22,26,27,27,40,33,
2126,27,22,26,26,27,31,35,22
Solution
since we are to use the class width (5) that mean we should give 5 as the gap,so we are going to start from the lowest value(21) and end at 25. don't make mistake that is the same as (21,22,23,24,25) so it shouldn't be 26 because we have 5 as the width 21 must be included too. so this is the table.
height | Frequency |
---|---|
21-25 | 8 |
26-30 | 23 |
31-35 | 10 |
36-40 | 9 |
How to contrust class-interval table using R
Now that we have get to know what we need to construct it is very easy to construct the table using code.
we need to write all data under height and the frequency here is the code below.
Codes>>
Height=c('21-25',"26-30","31-35","36-40")
Frequency=c(8,23,10,9)
Table=data.frame(Height,Frequency)
Table
Result>>
> Height=c('21-25',"26-30","31-35","36-40")
> Frequency=c(8,23,10,9)
> Table=data.frame(Height,Frequency)
> Table
Height Frequency
1 21-25 8
2 26-30 23
3 31-35 10
4 36-40 9
>
Now I believe you now understand how to construct any kind of table using code. try to solve some problem in statistic using this method. if you have any question you can comment below or chat me up on whatsApp (07045225718)
. Enjoy coding.
🔥 Introduction to R (1)
🔥 Data Structure (2)
🔥 Statistical value (mean, median, mode etc) (3)
🔥 Tabular Presentation of Data (4)
🔥 Ploting graph with R
🔥 constructing frequency distribution with R (6)
🔥 how to use R-programming to calculate Arithmetic,Geometric and Harmonic mean.
Posted on April 18, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.