Mode and Vector
Quantitative Trading
Online Flipped Classroom
English Medium Instruction
Jen-We Yang
Introduction to mode and vector
Mode describes the data type.
Vector is the most basic object in R language.
Other objects, such as matrix and data frame, are constructed
from vector object.
Vector and mode are very, very, very important.
It is necessary to lay a good foundation of vector &
mode for learning other objects efficiently.
What is data type & mode?
Example or explanation
Data type
mode (x)
1. Numeric (real) number
numeric
EX: 2, 0.5, -15
2. Complex number
complex
3. Character
character
EX: 3+4i, -2i, 1i
In computer science, a character is a unit of information
corresponding to a grapheme or symbol, such as letters,
numerical numbers, punctuation marks, whitespace, and so on.
4. Logic
5. Missing value
In R, any mode between two double quotation marks is
Character.
EX: "Who are you? ", "嗨", "3+1=4", "TRUE", "F", "NA", "NaN".
logical
True (T) or False (F)
numeric
NaN (Not a Number)
logical
NA (No available)
Rules for modes on a vector
Missing values can be mixed with other modes in a vector.
If you input different models into a vector, R language will transform
them to the same model according to the transform order.
Priority
Mode(x)
1
2
character complex
3
4
numeric
logical
Given a vector x, but we don't know its elements.
Mode(x)
Elements of x
Logical numeric
complex
T;F
NA
T;F
NA
Numeric
NaN
Complex
T;F
NA
Numeric
NaN
character
T;F
NA
Numeric
NaN
Complex
Character
How to identify T , F, NA, Real number, NaN, Complex, Character?