Spring Deals - hours only!Up to 70% off on all courses and bundles.-Close
What are vectors?
Vector operations
Indexing and filtering
Simple analysis
Summary

Instruction

Well done! The great thing about R is that it also allows you to easily visualize your data. There are lots of built-in functions that are used for plotting. For a numeric vector, you can use a histogram to see the distribution of its elements. In R, a histogram is displayed with the function hist(), which takes a single vector as its argument, e.g.:

hist(ages)

After this function call, R will return the following plot:

histogram_image

As you can tell, the elements of our vector have been divided into ranges (in our case, the ranges are 20-25, 25-30, 30-35, 35-40, and 40-45). Each range (called a bucket) has its own corresponding height and represents the number of vector elements that fall within that range. The taller the bucket, the more elements the corresponding range contains.

Exercise

Let's return to our salary example. Make a histogram for the vector named salaries.