| 准备工作 |
|---|
| getwd() |
| setwd() |
| dir() |
| 数据导入 |
|---|
| x=scan(“data.dat”) |
| read.delim() |
| read.table(“data.txt”) |
| 对象 | 形式 |
|---|---|
| 向量vector | x=c(1,2,3) |
| 矩阵(默认按列排)matrix | Xmat=matrix(c(1,3,5,7,9,11),nrow=3) |
| 数组array | 高维矩阵(三维矩阵) pql |
| 数据框data.frame | |
| 列表list | |
| 时间序列ts |
| 基本函数 | |
|---|---|
| exp() | |
| log() | |
| log10() | |
| gamma() | |
| lgamma() | |
| prod() | 连乘 |
| length | 向量长度 |
| cumsum() | 累加 |
| cumprod | 累乘 |
| fft() | 傅立叶变换 |
| which.min(x) | 最小值在哪里 |
| which.max(x) | 最大值在哪里 |
| summary() | 给出5个基本量的描述 |
用来提取指定行
newdata <- olddata[,c(1,3,5,7,9,11,13,15,17)]
用来删除列表中的某行
例子,删除第七行
y2<-y[-7,]
读取文件
注意有些看起来是空格实际上是tab
此时记得用分隔符
setwd("/Users/zhuxueling/Documents/Wichern_data")
x1<-read.table("T1-9.dat",sep = "\t")
计算多维数据的均值、相关系数、协方差矩阵
nd2<-d1[c(70:98),]
a<-summary(nd1)
cov(nd2)
cor(nd2)

2963

被折叠的 条评论
为什么被折叠?



