初始R 語言

   從0開始R語言。

既然什麼都不知道,那就從google開始。下面是維基百科的一段話,個人覺得給我對R語言的理解還是蠻有幫助的。 

     (摘自http://en.wikipedia.org/wiki/R_programming_language

R is a free software programming language and software environment for statistical computing and graphics. The R language is widely used among statisticians and data miners for developing statistical software and data analysis.Polls and surveys of data miners are showing R's popularity has increased substantially in recent years.

R is an implementation of the S programming language combined with lexical scoping semantics inspired by SchemeSwas created by John Chambers while at Bell Labs. R was created by Ross Ihaka and Robert Gentleman at theUniversity of Auckland, New Zealand, and is currently developed by the R Development Core Team, of which Chambers is a member. R is named partly after the first names of the first two R authors and partly as a play on the name of S.

R is a GNU project. The source code for the R software environment is written primarily in CFortran, and  R is freely available under the GNU General Public License, and pre-compiled binary versions are provided for various operating systems. R uses a command line interface; however, several graphical user interfaces are available for use with R.

個人對這段話其中部分簡單的翻譯了下:R語言是用於統計計算和作圖的免費的軟件編程語言和軟件環境。它被廣泛的用於統計學家開發統計軟件和數據挖掘者進行數據分析。R語言是在S編程語言上結合lexical scoping的一種實現。R是一個GNU項目,其源碼是由C,Fortran編寫。R語言用的是命令行接口,當然一些圖形用戶接口對R語言也是適用的。

那還等什麼呀,開始吧。

下載R-3.0.0-win.exe,安裝並運行

> x<-c(1,2,3,4,5,6) #新建一個有序vector
> y<-x^2
#求平方
> print(y)
#打印出vector y
[1]  1  4  9 16 25 36
> mean(y)
#求平均數
[1] 15.16667
> var(y)
#求方差
[1] 178.9667
> lm_1<-lm(y~x)
#y與x之間的線性關係
> print(lm_1)


Call:
lm(formula = y ~ x)


Coefficients:
(Intercept)            x  
     -9.333        7.000  


> summary(lm_1)
#對lm_1線性模型對象進行計算和打印


Call:
lm(formula = y ~ x)


Residuals:
      1       2       3       4       5       6 
 3.3333 -0.6667 -2.6667 -2.6667 -0.6667  3.3333 


Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  -9.3333     2.8441  -3.282 0.030453 *  
x             7.0000     0.7303   9.585 0.000662 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


Residual standard error: 3.055 on 4 degrees of freedom
Multiple R-squared:  0.9583,    Adjusted R-squared:  0.9478 
F-statistic: 91.88 on 1 and 4 DF,  p-value: 0.000662


> par(mfrow=c(2,2))
#請求2*2的佈局圖
> plot(lm_1)
#繪製迴歸模型診斷圖

太神奇了。接下來的就是系統的學習R語言,希望自己能快速進步!

   
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章