statistical value with R-programming
Tags: rprogramming, tutorial, devops, discuss
Published: 2021-03-31 00:32:55

#### 🔥[  Introduction to R (1)](https://dev.to/maxwizard01/introduction-to-r-programming-2add)
#### 🔥[ Data Structure (2)](https://dev.to/maxwizard01/data-structure-in-r-programming-2e6k)
#### 🔥[ Statistical value (mean, median, mode etc) (3)](https://dev.to/maxwizard01/statistical-value-with-r-programming-dcc)
#### 🔥[ Tabular Presentation of Data (4)](https://dev.to/maxwizard01/how-to-construct-table-using-r-programming-317c)
#### 🔥[ Ploting graph with R](https://dev.to/maxwizard01/ploting-graph-with-r-programming-3om7)
#### 🔥 [constructing frequency distribution with R (6)](https://dev.to/maxwizard01/how-to-construct-table-using-r-programming-317c)
 how do we calculate mean,median,mode etc.
let me start by saying to calculate them is just as easy as typing 3+3 to add two number on your calculator. the logic is that we make use of some inbuilt function in R. these are the inbuilt function and what we use them for.
`mean()` :- to calculate the mean of the data.
`median()` :- to calculate the median of the data
`sort()` :- to arrange the data in ascending order.
`var()` :- to calculate the varience
`sd()` :- to calculate the standard deviation
`range()` :- to calculate the range 
`sum()`:- to calculate the sum
`min()` :- to get the minimum value from the list or vector.
`max()` :- to get the maximum value from the list or vector.

Now let's try to make use each one of them 

### Example
let's say we have the following data as the score of 20 student in STA114 test below. 
22,22,12,25,23,21,11,13,12,25,26,21,12,11,22,11,16,17,18,28,29,10,20 and 8. 
the question is to calculate
i. the mean
ii. the median
iv. standard deviation
v. variance
vi. range
  
### solution
we need to write all the data as vector then proceeding to solve all the question by assigning the formula to suitable variable and print the answer with the following codes
```
allScore=c(22,22,12,25,23,21,11,13,12,25,26,21,12,11,22,11,16,17,18,28,29,10,20,8)
meanScore=mean(allScore)
print(meanScore)
medianScore=median(allScore)
print(medianScore)
S.D=sd(allScore)
print(S.D)
variance=var(allScore)
print(variance)
range=range(allScore)

```
Result
```
Score=c(22,22,12,25,23,21,11,13,12,25,26,21,12,11,22,11,16,17,18,28,29,10,20,8)
> meanScore=mean(allScore)
> print(meanScore)
[1] 18.125
> medianScore=median(allScore)
> print(medianScore)
[1] 19
> S.D=sd(allScore)
> print(S.D)
[1] 6.347286
> variance=var(allScore)
> print(allScore)
 [1] 22 22 12 25 23 21 11 13 12 25 26 21 12 11 22 11 16 17 18 28 29 10 20  8
```
Now to find the range we know that range is the largest data minus the smallest data. so to know the largest and the smallest we need to arrange the data in ascending order then pick the last and first (biggest and smallest) and subtract.
look at the code below
```R
arrangedScore=sort(allScore)
biggest=arrangedScore(arrangedScore[25])
smallestScore=arrangedScore([1])
print(biggest)
print(smallestScore)
```
#### 🔥[  Introduction to R (1)](https://dev.to/maxwizard01/introduction-to-r-programming-2add)
#### 🔥[ Data Structure (2)](https://dev.to/maxwizard01/data-structure-in-r-programming-2e6k)
#### 🔥[ Statistical value (mean, median, mode etc) (3)](https://dev.to/maxwizard01/statistical-value-with-r-programming-dcc)
#### 🔥[ Tabular Presentation of Data (4)](https://dev.to/maxwizard01/how-to-construct-table-using-r-programming-317c)
#### 🔥[ Ploting graph with R](https://dev.to/maxwizard01/ploting-graph-with-r-programming-3om7)
#### 🔥 [constructing frequency distribution with R (6)](https://dev.to/maxwizard01/how-to-construct-table-using-r-programming-317c)