基本知识
向量
数据框
矩阵
数组
向量
标量:一个元素
向量:多个元素
x<-c(1,2,3)
x<-(1:10)
x<-seq(1,10,by=0.5)
x<-rep(1:3,times=2)
向量中提取元素
x[2]
x[-2]
x[2:4]
x[-(2:4)]
x[c(1,5)]
数据框
- 读取数据
read.table(file="huahua.t.txt",sep = "\t",header =T)
a<-read.table(file = "huahua.txt",sep = "\t",header =T)
- 行名和列名
X<-read.csv('doudou.txt')
colnames(X)
rownames(X)
colnames(X)[1]<-"bioplanet"
X<-read.csv(file = "huahua.txt",sep = "\t",header =T,row.names=1)
- 导出
write.table(X,file = "yu.txt",sep = ",",quote=F)
- 变量保存与重新加载
save(frame1,file="frame1.RData")
save.image(file="bioinfoplanet.RData")
load("frame1.RData")
- 提取元素
X[x,]
X[,y]
X[y]
X[a:b]
X[c(a,b)]
X$列名