R语言入门班

感谢: 吴明昊老师 Swirl包作者 《Elegant Graphics for Dataanlysis》书作者 《R Graphics Cookbook》书作者

第一课  R初体验(12 h)
1、安装R
2、安装RStudio
3.在RStudio下输入以下命令:
install.packages("swirl")
安装Swirl
4、调用Swirl:
library(swirl)swirl()install_from_swirl("R Programming")
然后就可以开始使用Swirl了。
theme_set(theme_bw())
R工作目录
file.create("mytest.R")
list.files()
unlink('testdir2',recursive= TRUE)
加载数据
R中数组
c(1,1,2,4,5,7)
attach(mpg)
save(baochunsm,"wenjianming")
ggsave("*.png",width =5,height=5)

R中向量
paste(my_char,collapse =" ")
plotmath

R中缺失值处理
NA
NaN
To generate NaN,try dividing (using a forward slash) 0 by 0 .

R构造子集向量

矩阵和数据结构
my_matrix2<- matrix(1:20,4,5)
cbind(patients,my_matrix)
colnames(my_data) <- cnames
R中逻辑表达式
all
any
R中功能
R中申请和供给
lapply
sapply
vapply and tapply

flips <- sample(c(0,1), 100, replace = TRUE, prob = c(0.3, 0.7))

模拟
仿真

3D图包 (latticeExtra)
第二课 R基本语法
youtube学习
ggplot2:Elegant Graphics for Dataanlysis
http://www.cookbook-r.com/Graphs/
http://www.datavizcatalogue.com
#Referrence Book

#ggplot2: Elegant Graphics for Data Analysis (Use R!): 
#http://www.amazon.com/ggplot2-Elegant-Graphics-Data-Analysis/dp/0387981403

#R Graphics Cookbook: 
#http://www.cookbook-r.com/Graphs/
#http://www.amazon.com/R-Graphics-Cookbook-Winston-Chang/dp/1449316956

#install.packages("ggplot2")
library(ggplot2)


#Scatter Plot
plot(mtcars$wt, mtcars$mpg)

#Line Graph
plot(pressure$temperature, pressure$pressure, type="l")
points(pressure$temperature, pressure$pressure) #add points

lines(pressure$temperature, pressure$pressure/2, type="l",col="red")
points(pressure$temperature, pressure$pressure/2,col="red")

#Bar Graph
barplot(table(mtcars$cyl))

#Histogram
hist(mtcars$mpg, breaks=10)

#Box Plot
boxplot(mtcars$mpg)

#Plotting a Function Curve
curve(x^3 - 5*x, from=-4, to=4)
myfun <- function(xvar) {
  1/(1 + exp(-xvar + 10))
}
curve(myfun(x), from=0, to=20)


#Basic use
dat=diamonds
qplot(carat, price, data = diamonds)
qplot(log(carat), log(price), data = diamonds)
qplot(carat, x * y * z, data = diamonds)

#Colour, size,
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值