Learning R in Practice

Atomic

In reality there is no atomic variable in R. Each variable is a kind of array (list, vector or matrix). However it is still worth to understand the basis elements in R.

Type, class and mode

To learn a variable's basic type, we could use three ways:

class(var)
mode(var)
typeof(var)

These three are different:

  • class() shows the class,
  • mode() shows the storage type,
  • typeof() shows the internal type or the storage mode.

Missing Value

Missing value is very common in data analysis. And R handles this problem pretty well.

NA

NA represents Not Available, operations with NA result NA. So if we compare an NA to NA, we would get NA.

NA==NA  # results NA

To check whether a variable is NA, we could use is.na() to examine whether each element in a vector is an NA.

NaN

NaN represents Not a Number. Typically it is result from an ill-formulated equation.

Inf

Inf is not a missing value, it represents infinity. It can be used as other number in arithmetic operations, i.e.:

Inf + 1 # is Inf
1/Inf   # is 0