Data types in R

As discussed in Chapter 3Data Wrangling with R, there are five data types in R:

  • Character: For string values
  • Numeric: For numbers with decimal places (for example, 1.2, 3.45, and so on)
  • Integer: For whole numbers (for example, 1, 2, 3, and so on)
  • Logical: For Boolean values, TRUE and FALSE
  • Complex: For numbers that have an imaginary component (for example, 5 + 3i)
Note that, in R, we often use numerical and integer values interchangeably. In fact, an integer value is also a numeric quantity. The main benefit of using numeric instead of integer is that we can represent much larger numbers with the numeric data type.

It is useful to note here that in R, categorical values are generally represented as factors. When reading ...

Get Hands-On Data Science with R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.