4、Mastering R: From Function Creation to Practical Applications

Mastering R: From Function Creation to Practical Applications

1. Introduction to R’s Plotting and Function Capabilities

R offers a wide range of functions for data visualization and analysis. For example, the polygon function can be used to approximate the range of 100 Brownian motions and a 90% confidence band. Here is the code to achieve this:

par(mar=c(2,2,2,2))
x=matrix(0,ncol=100,nrow=10^4)
for (t in 2:10^4)
  x[t,]=x[t-1,]+rnorm(100)*10^(-2)
plot(seq(0,1,le=10^4),x[,1],ty="n",
     ylim=range(x),xlab="",ylab="")
polygon(c(1:10^4,10^4:1)/10^4,c(apply(x,1,max),
     rev(apply(x,1,min))),col="gold",bor=F)
polygon(c(1:10^4,10^4:1)/10^4,c(apply(x,1,quantile,.95),
     rev(apply(x,1,quantile,.05))),col="brown",b
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值