18. Basic Statistics

Some of the most common tools used in statistics are means, variances, correlations and t-tests. These are all well represented in R with easy-to-use functions such as mean, var, cor and t.test.

18.1 Summary Statistics

The first thing many people think of in relation to statistics is the average, or mean, as it is properly called. We start by looking at some simple numbers and later in the chapter play with bigger datasets. First we generate a random sampling of 100 numbers between 1 and 100.

> x <- sample(x=1:100, size=100, replace=TRUE) > x   [1] 53 89 28 97 35 51 21 55 47  3 46 35 86 66 51 20 41 15 10 22 31  [22] 86 19 13 10 59 60 58 90 11 54 79 45 49 23 91 80 30 83 69 20 76  [43]  2 42 ...

Get R for Everyone: Advanced Analytics and Graphics, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.