This line is using 1 hashtag.

This line is using 2 hashtags.

This line is using 3 hashtags.

This line is using 4 hashtags.

This line is BOLDED using double stars around it (without spaces).
This line is ITALIC using single star around it (without spaces).

# basic maths
2 + 3 
## [1] 5
2 * 3 - 5
## [1] 1
# generate vector weekdays
weekdays <- c("Monday", "Tuesday", "Wednesday", "Thursday","Friday")
weekdays
## [1] "Monday"    "Tuesday"   "Wednesday" "Thursday"  "Friday"
# generate vector random.number
random.number <- c(1, 2, 3, 4, 2, 3, 4, 6)
random.number
## [1] 1 2 3 4 2 3 4 6

VECTORS

rep() - replication function - make vector of repeated values.

There are 2 types of replication:

  1. Vector-wise: repeat the whole vector in the same original order:

    rep( value/vector , #time-repeat )

# generate vector score including: 10, 10, 10
score <- rep(10, 3)
score
## [1] 10 10 10
# generate vector weekdays 5 times
weekdays_rep <- rep(weekdays, 5)
weekdays_rep
##  [1] "Monday"    "Tuesday"   "Wednesday" "Thursday"  "Friday"    "Monday"   
##  [7] "Tuesday"   "Wednesday" "Thursday"  "Friday"    "Monday"    "Tuesday"  
## [13] "Wednesday" "Thursday"  "Friday"    "Monday"    "Tuesday"   "Wednesday"
## [19] "Thursday"  "Friday"    "Monday"    "Tuesday"   "Wednesday" "Thursday" 
## [25] "Friday"
  1. Component-wise: repeat EACH component at a time before moving on the the next component.

    rep( value/vector , each= #time-repeat )

# repeat weekdays component-wise 3 times
weekdays_component.wise <- rep(weekdays, each= 3)
weekdays_component.wise
##  [1] "Monday"    "Monday"    "Monday"    "Tuesday"   "Tuesday"   "Tuesday"  
##  [7] "Wednesday" "Wednesday" "Wednesday" "Thursday"  "Thursday"  "Thursday" 
## [13] "Friday"    "Friday"    "Friday"

seq() - sequence function - generate sequence of numbers.

seq( from=  , to=  , by=  )  

- `from=1` by DEFAULT or the number you want to start with.   
- `to=1` by DEFAULT or the number you want to end INCLUSIVELY.  
- `by=1` by DEFAULT or the number you want to step UP/DOWN.   
# DEFAULT
seq()
## [1] 1
# from 0 to 9, 2 step up at a time
seq(0, 9, 2)
## [1] 0 2 4 6 8
# from 43 to 34, step down 2.5 at a time
seq(43, 34, -2.5)
## [1] 43.0 40.5 38.0 35.5

SPECIAL CASE: length=

seq( from= , to= , length= )   

Note that: we cannot use `length=` and `by=` at the same time.  
# from 12 to 35 increasingly and consisting of 5 values
seq(12, 35, length= 5)
## [1] 12.00 17.75 23.50 29.25 35.00

FACTOR

Factors = CATEGORICAL vector containing QuaLitative data (NOMINAL).

Ordered Factors = ranked factors (ORDINAL).

weekdays
## [1] "Monday"    "Tuesday"   "Wednesday" "Thursday"  "Friday"
# convert weekdays into a factor
factor(weekdays)
## [1] Monday    Tuesday   Wednesday Thursday  Friday   
## Levels: Friday Monday Thursday Tuesday Wednesday
weekdays_rep <- factor(weekdays_rep)
weekdays_rep
##  [1] Monday    Tuesday   Wednesday Thursday  Friday    Monday    Tuesday  
##  [8] Wednesday Thursday  Friday    Monday    Tuesday   Wednesday Thursday 
## [15] Friday    Monday    Tuesday   Wednesday Thursday  Friday    Monday   
## [22] Tuesday   Wednesday Thursday  Friday   
## Levels: Friday Monday Thursday Tuesday Wednesday
factor( vector , order= TRUE, levels = c() )   
weekdays_component.wise
##  [1] "Monday"    "Monday"    "Monday"    "Tuesday"   "Tuesday"   "Tuesday"  
##  [7] "Wednesday" "Wednesday" "Wednesday" "Thursday"  "Thursday"  "Thursday" 
## [13] "Friday"    "Friday"    "Friday"
weekdays_component.wise <- factor(weekdays_component.wise, order = TRUE, levels = c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday"))

str() - check the structure of the variable

str(weekdays_rep)
##  Factor w/ 5 levels "Friday","Monday",..: 2 4 5 3 1 2 4 5 3 1 ...
str(weekdays_component.wise)
##  Ord.factor w/ 5 levels "Monday"<"Tuesday"<..: 1 1 1 2 2 2 3 3 3 4 ...