Book Image

R Programming Fundamentals

By : Kaelen Medeiros
Book Image

R Programming Fundamentals

By: Kaelen Medeiros

Overview of this book

R Programming Fundamentals, focused on R and the R ecosystem, introduces you to the tools for working with data. You’ll start by understanding how to set up R and RStudio, followed by exploring R packages, functions, data structures, control flow, and loops. Once you have grasped the basics, you’ll move on to studying data visualization and graphics. You’ll learn how to build statistical and advanced plots using the powerful ggplot2 library. In addition to this, you’ll discover data management concepts such as factoring, pivoting, aggregating, merging, and dealing with missing values. By the end of this book, you’ll have completed an entire data science project of your own for your portfolio or blog.
Table of Contents (6 chapters)

Factor Variables

We discussed variable types in Chapter 1, Introduction to R, but did not include factor variables because they're a special type of variable in R that you must often create yourself. In this section, we'll learn what a factor variable is, when to use a factor variable, how to create one, what the levels of a factor are, and how to change the levels.

A factor variable in R is an explicitly declared categorical variable, or one that defines different categories or levels. Some common examples of factor variables include a variable describing sex, month, or one designating low/medium/high.

Recall our discussion of variable classes and types from Chapter 1, Introduction to R. A factor variable will always be of class factor, but can be any type: character, numeric, integer, or otherwise. For example, a variable indicating month can have the months as type...