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 a CSV file using the inbuilt read.csv function, R attempts to read all character columns as factors, unless the behavior is suppressed using the command, options(stringsAsFactors=F) .

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.18.198