Skip to Content
R Programming Fundamentals
book

R Programming Fundamentals

by Kaelen Medeiros
September 2018
Beginner
206 pages
4h 27m
English
Packt Publishing
Content preview from R Programming Fundamentals

Factor Variables

We input a few variables from mtcars into plot(), but they were continuous. What happens if, instead, we input a factor variable?

For example, the cyl variable in mtcars gives the number of cylinders each car has. If we input it as a factor variable into plot, we get a bar chart (histogram) by default, where each bar gives a count of how many cars have each number of cylinders:

plot(as.factor(mtcars$cyl))

Let's now create plots using factor variables and learn to differentiate between plots created with factor variables and those created without. Follow the steps given below:

  1. Load the mtcars dataset using the data("mtcars") ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

R Programming Fundamentals

R Programming Fundamentals

Samik Sen, Marcin Dubel
Python for Programmers

Python for Programmers

Paul Deitel, Harvey Deitel

Publisher Resources

ISBN: 9781789612998Supplemental Content