R Summaries
A summary is a small set of key numbers that describes a whole set of values. It shows the spread and the centre in two short lines.
Six numbers at once
summary takes the whole set of scores at once. The output shows six numbers in two short lines.
scores <- c(55, 60, 62, 64, 66, 100)
print(summary(scores))Median beside mean
The first print shows the median of the scores. The second print shows the mean of the same scores.
scores <- c(55, 60, 62, 64, 66, 100)
print(median(scores))
print(mean(scores))Stats on a frame column
The first print shows the mean of the score column in the team frame. The next two prints show the smallest and largest scores in that column.
team <- data.frame(name = c("Ana", "Ben", "Cid"), score = c(72, 85, 90))
print(mean(team$score))
print(min(team$score))
print(max(team$score))Example
grades <- factor(c("low", "high", "low", "mid", "low", "high"))
print(summary(grades))Key points
- summary() prints six numbers for a numeric vector.
- The six numbers run from the smallest value to the largest value.
- The median is the middle value of the set.
- Half of the values sit at or below the median.
- The mean and the median differ when values lean to one side.
- summary() counts the values in each level of a factor.
In this example, summary() counts how many values fall in each level of the factor. The counts show that low appears most often.
Note
One summary call can replace several separate calls.
Try it Yourself
Edit the code, then press Run.
Running is simulated ยท rdrr.io R Snippets
Exercise
What does the median of a set of values give?