Select Page

Based on test data set 1:

People usualy mixed words average and mean and median. Because this word is used in several different ways. Usualy “average” means “arithmetic mean”:

• ```> mean(data\$age)
[1] 40.97
```

Median is the value which is directly in the middle if we look at data ordered in ascending order.

• ```> median(data\$age)
[1] 41.5
```

Mode is value which appears in data set most often. R has command “mode” but this shows type of variable. Statistical mode we can get this way:

• ```> names(sort(-table(data\$age)))[1]
[1] "25"

# explanation:
> -table(data\$age)

18 21 22 24 25 26 28 29 30 31 32 33 34 36 37 38 40 41 42 43 44 45 46 48 49 50
-1 -1 -5 -5 -7 -5 -2 -3 -3 -2 -2 -3 -2 -2 -1 -2 -2 -2 -3 -4 -2 -3 -3 -2 -2 -2
51 54 55 57 58 59 60 61 62 63 64 65
-1 -4 -5 -3 -1 -1 -4 -3 -2 -1 -3 -1

> sort(-table(data\$age))

25 22 24 26 55 43 54 60 29 30 33 42 45 46 57 61 64 28 31 32 34 36 38 40 41 44
-7 -5 -5 -5 -5 -4 -4 -4 -3 -3 -3 -3 -3 -3 -3 -3 -3 -2 -2 -2 -2 -2 -2 -2 -2 -2
48 49 50 62 18 21 37 51 58 59 63 65
-2 -2 -2 -2 -1 -1 -1 -1 -1 -1 -1 -1

```