Types of Data#
Understanding the different types of data and how R handles them is crucial. It might be tempting to skip over these technical details, but doing so could lead to some frustrating issues later on. For instance, you may have already encountered a problem when trying (and failing) to add two character objects together using the + operator.
R recognizes six basic data types: numeric, integer, logical, complex, character, and raw. You might notice that we’ve only mentioned five here—raw data isn’t covered because it’s rarely useful (99.99% of the time). We also won’t dive into complex numbers, as they’re not typically necessary for most users.
Key data types in R#
Numeric: These are numbers that can contain a decimal point. They can also be whole numbers, but R still treats them as numeric.
Integer: These are whole numbers without a decimal point.
Logical: Logical data can take on one of two values: TRUE or FALSE. There is also a special type of logical value called NA, which represents missing data.
Character: Character data represent string values, which can be thought of as words or phrases. A special type of character data is a factor, which is essentially a string with additional attributes, such as levels or an order. We’ll cover factors in more detail later.
Factor:Factors are used to represent categorical data and can be ordered or unordered. They are stored as integers with corresponding labels.