2017年10月8日 星期日

R一行文:if-else變形

如同《Python一行文:if-else變形》,簡單的if-else判斷在R語言也可以寫成一行文,請見下列範例:
  1. x <- 5
  2. ifelse(x > 0, 'Positive', 'Negative or Zero')
    [1] "Positive"
  3. x <- -1
  4. ifelse(x > 0, 'Positive', 'Negative or Zero')
    [1] "Negative or Zero"
使用的語法:ifelse(test, yes, no)
  • test:可以判斷是非的物件
  • yes:當test測出來是TRUE,回傳的值
  • no:當test測出來是FALSE,回傳的值
_EOF_

2017年10月7日 星期六

R套件:corrplot

R的corrplot套件可將相關矩陣(correlation matrix)、信賴區間(confidence interval)圖形化,也能做矩陣重排(matrix reordering)。下圖為一個correlation matrix:
上圖只要輸入程式碼:
  1. library(corrplot)
  2. M <- cor(mtcars)
  3. corrplot.mixed(M, lower="pie", upper="circle")

2017年10月6日 星期五

2017年10月5日 星期四

《Space Oddity》

這位加拿大太空人叫Chris Hadfield,歌曲5m30s
改編自David Bowie's Space Oddity

2017年10月4日 星期三

介紹alchemistry的網站

Alchemistry.org介紹如何用電腦計算得到自由能的網站,認為這是現在鍊金術(modern alchemy)網站包含了下面幾個主題: