初始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语言,希望自己能快速进步!

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