👉 R:主要運算符號
  ■ 剛開始的時候,R的首要功能就是做向量(vector)運算
  ■ 大多數R的運算符號和功能函數都主要都是對向量做計算
   ■
數學運算符號和功能函數運算之後會產生數值向量
🌻 Bi-Operant Math Operations act Element-wise
[1]    1   20  300 4000🌻 When the lengths of the vectors are different …
[1] 20 40 60 80The shorter vector are repeated silently
[1] 10 10 30 20There is a warning when …
Warning in c(10, 20, 30, 40, 50, 60, 70, 80) + c(1, 2, 3): longer object length is not a
multiple of shorter object length[1] 11 22 33 41 52 63 71 82Logical Operations do comparisons and produce
logical vectors
  ■
條件運算符號和功能函數運算之後會產生邏輯向量
They compare numerics, strings, factors, Date, …
[1]  TRUE FALSE FALSE FALSEshorten vectors are also repeated
[1] FALSE FALSE  TRUE  TRUE❓ what happen if I do …
🌻 Test for equivalence (==) is different from the
assignment operator (=)
[1] FALSE FALSE  TRUE FALSE🌻 The Set Comparison Operator : %in%
測試向量元件是否屬與某一個集合
[1] FALSE FALSE  TRUE  TRUEThe above is the same as …
[1] FALSE FALSE  TRUE  TRUE%in% is
not important 集合元件的次序是不重要的but different from …
[1] FALSE FALSE FALSE FALSE== works element wise. thus, the sequence in the right
hand side vector of is important❓ What happen if I do …
❓ What if …
🌻 2 Notations of Assignment : = 和 <-
的效果是相同的
[1]  12  20 -15 -24🌻 Assignment (=) is different from Test for Eq.
(==), 但這兩個運算符號的效果完全不一樣
[1] TRUE TRUE TRUE TRUE❓ What happen if you do
Most R function take vectors as input (usually the first
argument.)
summary functions produce a single summaries/statistics
[1] 995[1] 248.8math functions produce vectors applies to every elements
[1] 6.215 2.996 4.317 5.991[1] 22.361  4.472  8.660 20.000功能選項(arguments):In addition to the input vector, most R function take extra arguments for options
[1] 2.699 1.301 1.875 2.602
💡 Arguments of Functions:
   ■
To be convenient and flexible, most R functions have many arguments with
   ■ Place cursor on the function name and press F1
to see the online help
   ■ Arguments can be given either 
   ■ Unnamed-arguments must be in
their exact position
   ■ Named arguments can be placed in any
order
💡 功能選項(arguments):
   ■
為了彈性,多數的功能都有很多個選項
   ■
為了方便性,多數的功能選項都有預設值
   ■
將滑鼠的遊標放在功能名稱上,按下F1鍵就可以看到功能的定義
  ■ 在功能定義中,每個選項都有一個名稱
   ■
假如果你根據功能定義之中各選項的次序來設定選項,就可以不用打選項名稱
(call by position)
   ■
假如果你指定選項名稱,選項的次序就不必和根據功能定義中的選項次序一樣
(call by name)
Default argument
[1] 6.908Argument by position
[1] 3Argument by names
[1] 3Argument by names in reverse order
[1] 3Quite often we need to cascade several functions, for example
[1] 2🌻
Pipe這一個運算符號可以避免功能呼叫過度巢套,讓程式碼比較符合實際的資料運算程序,比較容易讀懂,也比較不容易寫錯
[1] 2🌻 The %>% would make it easier
to apply a series of functions
[1] 2