1、赋值求与
x<-c(1,2,3,4,5,6,7,8)
y<-c(9,10,11,12,13,14,15,16)
length(x)
length(y)
x+y
2、赋值对象列表
ls()
rm(x,y)
rm(list=ls())
3、矩阵排布
x=matrix(data=c(1,2,3,4,5,6,7,8), nrow=2,ncol=4,byrow=TRUE)
x
y=matrix(data=c(9,10,11,12,13,14,15,16),nrow=2,ncol=4,byrow=TRUE)
y
x=matrix(data=c(x), nrow=2,ncol=4,byrow=TRUE)
x
y=matrix(data=c(y),nrow=2,ncol=4,byrow=TRUE)
y
3开方
sqrt(x)
x^2
4、随机数生成
x=rnorm(50)
y=rnorm(x+rnorm(50,mean=50,sd=、1))
x=rnorm(50)
5、代码一致的随机数
set、seed(100)
rnorm(150)
6、计算均值与方差
set、seed(100)
y=rnorm(150)
mean(y)
var(y)
sqrt(var(y))
sd(y)
7、图形输出
x=rnorm(100)
y=rnorm(100)
plot(x,y)
plot(x,y,xlab=”this is the x-axis”,ylab=”this is the y axis”,main=”Plot of X vs Y”)
pdf(“Figure、pdf”)
plot(x,y,col=”green”)
dev、off()
x=rnorm(100)
y=rnorm(100)
plot(x,y)
plot(x,y,xlab=”this is the x-axis”,ylab=”this is the y axis”,main=”Plot of X vs Y”)
jpeg(“Figure、jpeg”)
plot(x,y,col=”green”)
dev、off()
8、等比数列等差数列
x=seq(3、10)
x=seq(1,20)
x=seq(-pi,pi,length=50)
9、三维等高线图
x=seq(1,20)
x=seq(-pi,pi,length=50)
y=x
f=outer(x,y,function(x,y)cos(y)/(1+x^2))
contour(x,y,f)
contour(x,y,f,nlevels=45,add=T)
fa=(f-t(f))/2
contour(x,y,fa,nlevels=15)
10、热地图
x=seq(1,20)
y=x
f=outer(x,y,function(x,y)cos(y)/(1+x^2))
contour(x,y,f)
contour(x,y,f,nlevels=45,add=T)
fa=(f-t(f))/2
contour(x,y,fa,nlevels=15)
persp(x,y,fa)
persp(x,y,fa,theta=30)
persp(x,y,fa,theta=30,phi=20)
persp(x,y,fa,theta=30,phi=70)
persp(x,y,fa,theta=30,phi=40)
11、数据载入
Auto=read、table(“Auto、data”)
fix(Auto)
Auto=read、table(“Auto、csv”,header=T,na、strings=”?”)fix(Auto)
dim(Auto)
Auto[1:4,]
Auto=na、omit(Auto)
dim(Auto)
names(Auto)
12、图形数据汇总
Auto=read、table(“Auto、data”)
fix(Auto)
Auto=read、table(“Auto、csv”,header=T,na、strings=”?”)
fix(Auto)
dim(Auto)
Auto[1:4,]
Auto=na、omit(Auto)
dim(Auto)
names(Auto)
plot(Auto$cylinders,Auto$mpg)
attach(Auto)
plot(cylinders,mpg)
cylinders=as、factor(cylinders)
13、箱线图
plot(cylinders,mpg,col=”red”,varwidth=T,horizontal=T)
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- sarr.cn 版权所有 赣ICP备2024042794号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务