一、向量、标量
x<-c(1,2,3,4,5)
c(1:100)
seq(from=1,to=100,by=2)
seq(from=1,to=100,length.out=10)
rep(2,4)
rep(x,3)
x[x>3]
x[c(4:18)]
x[c(T,F)]
append(x=v,values=99,after=5)
y%%x
y%/%x
c(1,2,3) %in% c(1,2,3,4,5,6)
abs(x)
sqrt(x)
log(16,base=2)
log(16)
log10(10)
exp(x)
ceiling(c(-2.3,3.1415))
floor(c(-2.3,3.1415))
trunc(c(-2.3,3.1415))
round(c(-2.3,3.1415))
round(c(-2.3,3.1415),digits=2)
sin(x)
cos(x)
sum(x)
max(x)
min(x)
range(x)
mean(x)
var(x)
sd(x)
prod(x)
median(x)
quantile(x)
quantile(x,c(0.4,0.5,0.8))
which.max(x)
which.min(x)
二、矩阵与数组
m<-matrix(1:20,4,5)
m<-matrix(1:20,4,byrow=T)
m<-matrix(1:20,4,byrow=F)
dimnames(m)<-list(rnames,cnames)
dim(x)<-c(4,5)
dim1<-c("A1","A2")
dim2<-c("B1","B2","B3")
dim3<-c("C1","C2","C3","C4")
x<-array(1:24,c(2,3,4),dimnames=list(dim1,dim2,dim3))
state.x77[,"Income"]
state.x77["Alabama",]
rowSums(m)
colSums(m)
colMeans(m)
rowMeans(m)
n<-matrix(1:9,3,3)
t<-matrix(2:10,3,3)
n*t
n %*% t
diag(n)
三、列表
state.center
a<-1:20
b<-matrix(1:20,4)
c<-mtcars
d<-"this test"
mlist <-list(first=a,second=b,third=c,forth=d)
mlist[c[1,4]]
mlist$first
state.center$x
mlist[[1]]
四、数据框
data.frame
state$Murder
plot(women$height,women$weight)
lm(formula=weight~height,data=women)
?attach
attach(mtcars)
mpg
detach(mtcars)
五、因子
table(mtcars$cyl)
table(mtcars$am)
f<-factor(c("red","red","green","green","blue"))
plot(mtcars$cyl)
![在这里插入图片描述](https://img-blog.csdnimg.cn/56f39fe571a74fbba29d580195cb7908.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5aaC5p6c5oiR5piv5rip5biF5biF,size_15,color_FFFFFF,t_70,g_se,x_16)
plot(factor(mtcars$cyl))
![在这里插入图片描述](https://img-blog.csdnimg.cn/651113a6c7c4492ca0c86bf086a0c4f5.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5aaC5p6c5oiR5piv5rip5biF5biF,size_13,color_FFFFFF,t_70,g_se,x_16)
六、时间序列
airmiles
![在这里插入图片描述](https://img-blog.csdnimg.cn/08f1ee1f77b44700a52a9599215bd349.png)
sys.Date()
class(sys.Date())
a<-"2022-04-07"
as.Date(a,format="%Y-%m-%d")
?strftime
seq(as.Date("2020-01-01"),as.Date("2021-01-01"),by=1)
?ts
sales<-round(runif(48,min=50,max=100))
ts(sales,start=c(2010,5),end=c(2014,4),frequency=1)