Types

Types

Watch this video:

Atomic types

Which of these is not an atomic data type?








What type?

What type of data is "1L"?





Integers

Create a vector of integers from one to five. Can you imagine why you might want to use integers instead of numbers/doubles?

c(1L, 2L, 3L, 4L, 5L)

Floating point arithmetic

Computers must use a finite amount of memory to store decimal numbers (which can sometimes require infinite precision). As a result, some decimals can only be saved as very precise approximations. From time to time you’ll notice side effects of this imprecision, like below.

Compute the square root of two, square the answer (e.g. multiply the square root of two by the square root of two), and then subtract two from the result. What answer do you expect? What answer do you get?

sqrt(2) * sqrt(2) - 2
sqrt(2)^2 - 2

Vectors

How many types of data can you put into a single vector?




Character or object?

One of the most common mistakes in R is to call an object when you mean to call a character string and vice versa.

Which of these are object names? What is the difference between object names and character strings?







Next topic