6 A few important details

6.1 A primer on technicals

  • R is CaSe-SeNsItIvE, e.g., “Gender” is different than “gender”
  • Missing values are coded as NA (i.e., not available)

6.1.1 Variable types

  • character - Strings
  • integer - Integers
  • numeric - Integers + Rational + Irrational
  • factor - Categorical variable where each level is a category
  • logical - Boolean
  • complex - Complex numbers

6.1.2 Data types

  • vector - A collection of elements of same class
  • matrix - All columns must uniformly contain only one variable type.
  • data.frame - The columns can contain different classes.
  • list - Can hold objects of different classes and lengths

6.1.3 Classification of R Objects

This is important to learn and distinguish because in programming in R, you need to know the characteristics of the object you want to manipulate.

6.1.4 mode

There are five main types (technically “modes”) of R objects

  • integer & numeric: used for quantitative data. Our vector \(height\) is numeric.
  • character: used for qualitative data. When there is one string like “Hey There Mate” or a website address.
  • logical: TRUE or FALSE
  • list: special R object ()
  • function: sets of instructions contained in a sub program: e.g., mean()
[1] "numeric"

The mode of the R function \(mean()\) is ?

[1] "function"

In depth knowledge: ‘mode’, is a mutually exclusive classification of objects according to their basic structure. An object has one and only one mode. The ‘atomic’ modes are numeric, complex, character and logical. Recursive objects have modes such as ‘list’ or ‘function’ or a few others. The emphasis on “main” was given as there are also other types of storage modes (such as raw, complex and others) but we are not going to use them in this course - for more info check \(?mode\).

6.1.5 class

Here are some of common R classes

  • integer & numeric
  • character & factor
  • matrix (2D)
  • list & data.frame

In depth knowledge: ‘class’ is a property assigned to an object that determines how generic functions operate with it. It is not a mutually exclusive classification. If an object has no specific class assigned to it, such as a simple numeric vector, it’s class is usually the same as its mode, by convention. For more info check \(?class\).

[1] "numeric" "numeric"
[1] "character" "character"
[1] "logical" "logical"
[1] "data.frame" "list"      
[1] "data.frame" "list"      
[1] "numeric" "numeric"
[1] "matrix" "list"  
[1] "expression" "expression"
[1] "<-"   "call"
[1] "function" "function"

In depth knowledge: Optional read & info

There is an excellent discussion on the difference between mode, class, and other characteristics of R objects such as storage.mode and type of here.