[读书笔记] R语言实战 (一) R语言介绍

典型数据分析的步骤:

R语言:为统计计算和绘图而生的语言和环境

数据分析:统计学,机器学习

R的使用

1. 区分大小写的解释型语言

2. R语句赋值:<-

3. R注释: #

4. 创建向量 c()

5. 观察演示 列表demo(),图形演示demo(graphics)

6. 帮助函数

7. getwd()查看当前工作目录, setwd()设定当前工作目录

setwd('E:\\')
getwd()
[1] "E:/"

8. 工作空间管理函数  

9. 输入输出

1). 输入

source('filename') 在当前会话中执行一个脚本

2). 文本输出

sink('filename')输出重定向到文件filename, append=True追加文件

3). 图形输出

4). dev.off()输出返回到终端

#在当前会话中执行脚本
source("script1.R")
#文本输出 [追加] 到myoutput, 图形输出保存到mygraphs.pdf
sink("myoutput",append=TRUE, split= TRUE)
pdf("mygraphs.pdf")
source("script2.R")
#
sink()
#结果返回到终端
dev.off()
source("script3.R")

10.  包管理

#安装ggplot2包
install.packages("ggplot2")
#更新ggplot2包
update.packages("ggplot2")
#载入包
library(ggplot2)
#查看已加载包
(.packages())
#卸除包
detach("package:ggplot2")
#卸载包
remove.packages("ggplot2")

 

 

  

  

 

posted @ 2017-11-21 18:05  VincentCheng  阅读(515)  评论(0编辑  收藏  举报