1. Introduction
R is an object-oriented programming language. Almost anything in R could be an object.

2. Datatype in R
a. Summary
NB:
(1) numeric class in R should be double/floating point.
(2) We would say factor is something between class and structure. It is a structure but behave more like a class.
(3) Different with python, we call string as character in R.
(4) Some useful function to check the type of an object:
| Function | Application |
|---|---|
| typeof() | what is it? i.e. how is it saved in memory? (not common used) |
| class() | what is it? i.e. how is it used in functions? |
| str() | what is the structure? (frequently used, also tell you class) |
b. Logical values
Logical values are created by logical expressions. When coerced to numeric, TRUE = 1, FALSE = 0.
logical operators:


c. factor
Factors used for classification - categories
Take gender as an example:

d. special values
Missing numbers are NA
Undefined numbers (e.g. division by zero) are NaN

3. Frequently-used function:
| Function | application |
|---|---|
| c(x1, x2) | combine things together |
| min(x) | minimum value |
| max(x) | maximum value |
| range(x) | get the range.same as c(min(x),max(x)) |
| length(x) | get the length of x |
| sort(x) ; order(x, …) | sorting |
| sum() | sum |
| prod() | product |
| mean(), median(), sd(), var() | statistical functions to get mean, median, standard derivation, variance |
| summary(x) | statistical summary |
| paste() | see example below (detail see in ?paste()) |
paste() 函数:










